Metrics
Author metrics.yml: the name/measure/model/entities/time shape, metric types, and how to run a metric from the UI, the API, or AI Q&A.
What a metric is
A metric is a named number your team agrees on. Once you define active_arr in your semantic project, every chart, dashboard tile, alert, and AI Q&A answer that references it resolves to the same formula, filters, and time bucket.
Goni ships a semantic project with the core metrics. You add your own from the New metric form on the Metrics page, or by applying a metric an AI agent proposes; both store the shape described below. Goni compiles a metric to ClickHouse SQL on request, AND-merges your dimension and time filters, and returns rows. You can inspect the compiled SQL from the UI for any metric on any chart.
The metrics.yml shape
Metrics live under a version: 2 header as a flat list. Each entry ties a measure to a model, declares which dimensions it can be sliced by, and points at a timestamp column.
version: 2
metrics:
- name: active_arr
label: Active Annual Recurring Revenue
type: simple
measure: { type: sum, expr: arr_eur }
model: ref('fct_subscriptions')
filter: is_active = 1
entities: [country, plan]
time: { grain: week, column: started_at }
- name: active_customers
label: Active customers
type: simple
measure: { type: count_distinct, expr: customer_id }
model: ref('fct_subscriptions')
filter: is_active = 1
entities: [country, plan]
time: { grain: week, column: started_at }
Fields:
name- stable identifier,^[a-z][a-z0-9_]{0,62}$. Referenced by dashboards, alerts, and AI Q&A. Renaming breaks references, so treat it like a public API.label- human-readable string shown in the Metrics browser and in AI-generated chart titles.type-simpletoday.ratio,cumulativeandderivedare coming soon; see metric types below.measure-{ type, expr }.typeis one ofsum,count,count_distinct,avg,min,max.expris a column on the underlying model or a short arithmetic expression.model-ref('model_name')resolving to a model you defined under Sources and models.filter- optional SQL predicate AND-merged into the metric’s WHERE clause. Interpolated verbatim, so keep the expression trusted and reviewable inside yourmetrics.yml.entities- the list of dimensions the metric may be sliced by. Callers pass a subset of these per query.time-{ grain, column }.grainisday,week,month,quarter, oryear.columnis the timestamp used for bucketing.
Metric types
- Simple aggregation applies one measure to one model.
active_arr,active_customers, andmrrare simple metrics. - Coming soon: ratio. Divides one measure by another over the same grain. Useful for
arpu(revenue over customers) orattach_rate(paid over signed up). - Coming soon: cumulative. Rolls a measure forward over time. Useful for
lifetime_customersor a running total within a bounded window. - Coming soon: derived. Combines two or more existing metrics with a small expression. Useful for
net_revenue = gross_revenue - refundsorpaid_conversion = paid_signups / total_signups.
The churn_rate (ratio) and net_revenue (derived) entries below show the planned shape; until these types ship, Goni refuses them when you save them.
metrics:
- name: mrr
label: Monthly Recurring Revenue
type: simple
measure: { type: sum, expr: mrr_eur }
model: ref('fct_subscriptions')
filter: is_active = 1
entities: [country, plan]
time: { grain: month, column: started_at }
- name: churn_rate
label: Monthly churn rate
type: ratio
numerator:
measure: { type: count, expr: customer_id }
filter: churned_this_month = 1
denominator:
measure: { type: count, expr: customer_id }
filter: active_at_month_start = 1
model: ref('fct_subscription_activity')
entities: [country, plan]
time: { grain: month, column: month_start }
- name: net_revenue
label: Net revenue
type: derived
expression: gross_revenue - refunds
entities: [country, plan]
time: { grain: month, column: booked_at }
Running a metric
Three surfaces run the same compiled SQL.
Metrics browser (UI). Open the Metrics tab, pick a metric, choose a time range and dimensions from the picker, and hit Run. The result table renders below and a chart preview appears on the right. The compiled SQL is available under the “SQL” toggle on the same page.
Public API. POST /api/metric/{name}/query runs the same metric. The request body is optional; an empty body runs the metric with its declared defaults.
{
"dimensions": ["country"],
"filters": { "plan": "pro" },
"time_grain": "week",
"time_range": ["2026-01-01T00:00:00Z", "2026-08-01T00:00:00Z"],
"limit": 500
}
Response:
{
"metric": "active_arr",
"sql": "SELECT toStartOfWeek(started_at) AS ts, country, sum(arr_eur) AS value FROM marts_semantic.fct_subscriptions WHERE is_active = 1 GROUP BY ts, country ORDER BY ts",
"columns": ["ts", "country", "value"],
"rows": [{"ts": "2026-01-06", "country": "LT", "value": 481200}],
"stats": {"rows_returned": 32, "elapsed_ms": 41},
"cache": {"hit": false, "ttl_seconds": 60}
}
Pass ?refresh=1 to bypass the result cache. GET /api/metrics lists the metrics the caller is allowed to see.
AI Q&A (Ask). Ask a question in natural language (“What was our ARR by country last quarter?”). The planner picks one metric from the catalog, translates the phrase into dimensions, filters, and a time range, then runs it through the same query surface. It cannot invent a column or metric that is not defined in your metrics.yml. See Ask for the loop.
How dimensions and filters interact
entities is the allowlist of dimensions a metric may be sliced by. A query then passes:
dimensions- a subset ofentitiesto group by. Emits GROUP BY on those columns and returns one row per unique combination per time bucket.filters- equality filters keyed by a dimension name. Emits AND-merged predicates into WHERE.time_grainandtime_range- override the metric’s declared grain and window on a per-query basis.
Access control layers on top. Row filters, column masks, and metric allow-lists from Access control AND-merge into the same WHERE clause server-side. Callers cannot bypass them by editing the request body.
Compiled SQL you can inspect
The compiled SQL for any metric shows up in three places: the chart tile “SQL” toggle, the Metrics browser detail pane, and the sql field on every /api/metric/{name}/query response. It is the exact query Goni sent to your warehouse, including your row-filter policy and the metric’s static filter, ANDed together in a single SELECT.
Because the formula lives in metrics.yml under version control, tracing any number back is a three-step read: the YAML, the compiled SQL, and the referenced model.
Related
- Charts - how a chart binds to a metric and a query.
- Dashboards - tile-level filters flow through the same query surface.
- Alerts and scheduled reports - alerts poll a metric on their schedule.
- Access control - allow-lists, row filters, and column masks.
- Ask - grounded AI Q&A over the same metrics.
- Metric trust overlay - SQL + lineage + tests + freshness for any metric on any chart.
- Metric blame - line-level git blame for the YAML stanza that defines the metric.
Last updated