Dimension
Row attribute that breaks down or slices a measure. Examples: orders.status, orders.delivery_attempts, users.country.
AQLearn 1.3 / Concept
Source lesson: AQLearn 1.3: Dimensions and Measures. Tangible win: predict how dimensions change the shape of a measure result.
Row attribute that breaks down or slices a measure. Examples: orders.status, orders.delivery_attempts, users.country.
Aggregate value calculated across rows. Examples: count(orders.id), sum(order_items.quantity * products.price).
Rule of thumb: dimensions set the level of detail. Measures are recalculated once per dimension group.
AQLearn ships an ecommerce demo dataset. This lesson queries the highlighted orders model. Surrounding models are reachable through many-to-one relationships, so AQL can pull dimensions like users.gender or countries.name without explicit joins.
order_items.order_id > orders.id,
order_items.product_id > products.id,
orders.user_id > users.id,
users.city_id > cities.id,
cities.country_code > countries.code.
explore {
measures {
count_of_orders: orders | count(orders.id),
}
}
| count_of_orders |
|---|
| 2056 |
Without dimensions, the aggregate collapses all rows into one number.
explore {
measures {
count_of_orders: orders | count(orders.id),
}
dimensions {
order_status: orders.status,
}
}
| order_status | count_of_orders |
|---|---|
| delivered | 1488 |
| cancelled | 366 |
| refunded | 202 |
explore {
measures {
count_of_orders: orders | count(orders.id),
}
dimensions {
delivery_attempts: orders.delivery_attempts,
order_status: orders.status,
}
}
Result has nine rows (3 statuses x 3 delivery attempt values). Each row is one combination, with its own count.
order_status: orders.status,. Run.delivery_attempts: orders.delivery_attempts,. Run.Next: date_trunc() and time granularity. How to slice a measure by month, year, or quarter.