Concepts
Metrics
Reusable, named calculations agents and reports can query
A metric is a named calculation defined once on a dataset, in AMQL, so every agent and report that asks for "revenue" resolves against the same definition.
Defining a metric
Dataset sales {
metric revenue {
label: 'Total Revenue'
type: 'aggregate'
definition: @aql sum(orders.amount) ;;
format: 'currency'
}
metric average_order_value {
label: 'Average Order Value'
type: 'expression'
definition: @aql {{ revenue }} / {{ order_count }} ;;
format: 'currency'
}
}Metrics vs. measures
Measures live on a single data model and can only aggregate that model's own fields. Metrics live on a dataset and can combine fields across every model the dataset includes — use a measure for single-model aggregations, and a metric once you need to span models or build on other metrics.
Querying by dimensions
A metric has no grouping until it's combined with one or more
dimensions — for example, revenue grouped by
order_date at a monthly grain gives you revenue by month.
anfra query --metric revenue --by order_date --grain month