AQLearn 1.3 / Concept

Dimensions and Measures

Source lesson: AQLearn 1.3: Dimensions and Measures. Tangible win: predict how dimensions change the shape of a measure result.

Why this matters for your mission: when a metric returns "wrong" numbers, the dimension list is usually the cause. Knowing how dimensions slice measures is the first debug move.

Core idea

Dimension

Row attribute that breaks down or slices a measure. Examples: orders.status, orders.delivery_attempts, users.country.

Measure

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.

Dataset diagram

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.

N : 1 N : 1 N : 1 N : 1 N : 1 countries codetext, pk nametext continent_nametext cities idnumber, pk nametext country_codetext, fk users idnumber, pk nametext gendertext agenumber sign_up_atdatetime city_idnumber, fk orders this lesson idnumber, pk statustext created_atdatetime delivery_attemptsnumber discountnumber user_idnumber, fk order_items order_idnumber, fk product_idnumber, fk quantitynumber products idnumber, pk nametext pricenumber category_idnumber, fk merchant_idnumber, fk
Many-to-one relationships: 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.
primary key foreign key "many" side "one" side

Same measure, different dimensions

No dimension: grand total

explore {
  measures {
    count_of_orders: orders | count(orders.id),
  }
}
count_of_orders
2056

Without dimensions, the aggregate collapses all rows into one number.

One dimension: per status

explore {
  measures {
    count_of_orders: orders | count(orders.id),
  }
  dimensions {
    order_status: orders.status,
  }
}
order_statuscount_of_orders
delivered1488
cancelled366
refunded202

Two dimensions: per status and delivery attempts

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.

Customer-safe explanation: "Adding a dimension splits the same metric into more rows. Removing dimensions collapses it back into one total."

Heuristic: how many rows will I get?

Retrieval practice

1. An explore has zero dimensions and one measure count(orders.id). How many rows?
2. Adding a second dimension to an explore usually changes the result by...
3. orders.delivery_attempts is used to slice. It is a...
4. When you add a dimension, the measure is...

Do in AQLearn

  1. Open AQLearn Dimensions and Measures.
  2. Remove all dimensions and run. Confirm one row.
  3. Add back order_status: orders.status,. Run.
  4. Add delivery_attempts: orders.delivery_attempts,. Run.
  5. Read row count after each step and say out loud which dimensions slice the result.

Next local lesson

Next: date_trunc() and time granularity. How to slice a measure by month, year, or quarter.