count()
Counts values. Common for order count, user count, row count.
orders | count(orders.id)
AQLearn 1.2 / Function
Source lesson: AQLearn 1.2: Function: Aggregate Functions. Tangible win: choose the right aggregate function for a measure.
An aggregate function turns many field values into one summary value. If your explore has dimensions, the aggregate is calculated once per dimension group.
|
aggregate_func(model.field)
orders | count(orders.id)
count()Counts values. Common for order count, user count, row count.
orders | count(orders.id)
max()Returns highest value. For timestamps, highest usually means latest.
orders | max(orders.created_at)
min()Returns lowest value. For timestamps, lowest usually means oldest.
orders | min(orders.created_at)
avg()Returns average numeric value. Good for discount, age, duration.
orders | avg(orders.discount)
AQLearn asks you to extend count by status with latest order time, oldest order time, and average discount.
explore {
measures {
count_of_orders: orders | count(orders.id),
latest_order_time: orders | max(orders.created_at),
oldest_order_time: orders | min(orders.created_at),
avg_order_discount: orders | avg(orders.discount),
}
dimensions {
order_status: orders.status,
}
}
latest_order_time: orders | max(orders.created_at),.oldest_order_time: orders | min(orders.created_at),.avg_order_discount: orders | avg(orders.discount),.Next: dimensions and measures, why dimensions control the level of detail of each aggregate.