AQLearn 2.1 / Concept

Metric Expressions

Source lesson: AQLearn 2.1: Metric Expressions. Tangible win: separate the calculation of a number (metric) from the role it plays in a report (measure or dimension).

Purpose of this lesson

Have you ever tried to answer "We need order count on the dashboard, in the cohort table, and on the customer-detail page; can we make sure they all agree"?

You hit these pain points:

  1. Three reports re-implement the same calculation slightly differently and produce three different totals. The CEO catches it.
  2. When the business definition changes (for example, "only delivered orders count"), you have to find and edit every copy. Some get missed.
  3. You want the same calculation to appear sometimes as a chart number (a measure) and sometimes as a column you can group by (a dimension), but the syntax in your tool forces you to pick one.

This lesson solves it: define a calculation once as a metric expression, then plug it in wherever you need it. The same expression can power a measure or a dimension. Update the definition in one place and every report follows.

Why this matters for your mission: the metric-centric paradigm is the whole reason Holistics exists. Internalizing this distinction is what lets you defend "single source of truth" answers on presales calls.

Three words, three jobs

Metric

The named, reusable analytical value. Lives once in the dataset. Example: "order count".

Metric expression

The formula that calculates a metric. Example: orders | count(orders.id).

Measure / Dimension

The role the metric plays in a specific explore. Same expression, different slot.

Same expression, two slots

Metric expression orders | count(orders.id) one formula, one source of truth used inside measures { } Measure role "What number am I showing?" count_orders: orders | count(orders.id), used inside dimensions { } Dimension role "What am I grouping or labelling by?" y: orders.count_orders,
One expression. Two roles. Same number, different job in the report.

Reading the AQLearn example

metric orders_metric = orders | count(orders.id);

dimension orders.orders_metric_as_dim = orders_metric;

explore {
  measures {
    metric_as_measure: orders_metric,
  }
  dimensions {
    metric_as_dimension: orders.orders_metric_as_dim,
  }
}

Side by side: definition vs use

WhereYou writeYou get
Datasetmetric count_orders = orders | count(orders.id);a reusable name
Explore measurescount_orders, or x: orders | count(orders.id),a measure slot
Model dimensionsdimension orders.count_orders = orders | count(orders.id);a dimension slot
Explore dimensionsy: orders.count_orders,a dimension you can group by

Why a count can be a dimension

Once a metric is wrapped as a dimension, AQL treats its value as a label. You can:

Customer-safe explanation: "We define each business metric once. Reports use it as a chart number or as a grouping column without re-implementing the math."

Dataset diagram

The same AQLearn dataset. orders is the model that owns the example metric. Once orders_metric is defined on orders, every explore that joins to orders can use it.

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 orders_metric_as_dimmetric-as-dim order_items order_idnumber, fk product_idnumber, fk quantitynumber products idnumber, pk nametext pricenumber category_idnumber, fk merchant_idnumber, fk
orders grows a virtual field orders_metric_as_dim at the bottom: the same metric, attached to the model so it can be used as a dimension.
primary key foreign key

Retrieval practice

1. The formula orders | count(orders.id) is a...
2. "Measure" and "dimension" describe...
3. Can a single metric expression appear as both a measure in one report and a dimension in another?
4. If the business changes the definition of "order count", how many places must you update with metrics?

Do in AQLearn

  1. Open AQLearn Metric Expressions.
  2. Run the starter query. Confirm the same calculation appears as a measure and as a dimension column.
  3. Add a second measure named differently but using the same metric (orders_metric) to see reuse.
  4. Say out loud which words refer to the formula vs the role.

Next local lesson

Next: Pipe (1). How the | operator chains steps inside a metric expression.