Metric
The named, reusable analytical value. Lives once in the dataset. Example: "order count".
AQLearn 2.1 / Concept
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).
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:
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.
The named, reusable analytical value. Lives once in the dataset. Example: "order count".
The formula that calculates a metric. Example: orders | count(orders.id).
The role the metric plays in a specific explore. Same expression, different slot.
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,
}
}
metric orders_metric = ...: define the metric expression once, give it a name.dimension orders.orders_metric_as_dim = orders_metric;: promote the same metric to a dimension on the orders model so it can be used in dimensions { }.orders_metric appears as both a measure and a dimension. Same calculation, two roles.| Where | You write | You get |
|---|---|---|
| Dataset | metric count_orders = orders | count(orders.id); | a reusable name |
| Explore measures | count_orders, or x: orders | count(orders.id), | a measure slot |
| Model dimensions | dimension orders.count_orders = orders | count(orders.id); | a dimension slot |
| Explore dimensions | y: orders.count_orders, | a dimension you can group by |
Once a metric is wrapped as a dimension, AQL treats its value as a label. You can:
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.
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.
orders_metric) to see reuse.Next: Pipe (1). How the | operator chains steps inside a metric expression.