Metric Definitions That Scale
Write the recipe once; let everyone use it
Scalable metric definitions are written once, tested, versioned and owned in a semantic layer — so one shared definition can power every dashboard without forking.
What you will learn
- Structure a metric definition: measure, dimensions, filters, grain
- Make definitions testable and versioned
- Design metrics that compose into KPIs and time comparisons
What is this?
A scalable metric definition survives growth: it is written once in a shared, versioned semantic layer, structured as measure + dimensions + filters + grain, validated by tests, and owned by a human. Because it composes (into comparisons, rollups and targets), teams get consistency without duplicating logic.
Why do you need it?
- Spreadsheet-era habits (define it again in each workbook) do not survive 20 dashboards.
- Composable definitions enable self-service without turning users loose on raw data.
- Versioned definitions make changes auditable — you can see why a number moved.
- Tests catch the classic 'it worked locally' definition bugs before they hit production.
Mental model
A shared library of library functions
A scalable metric catalog
You don't rewrite sort() per application; you import the tested, versioned one. Metrics are the functions of the business — write and test them once, import everywhere, upgrade in tandem.
How it works
- The definition declares the numerator measure, the population (denominator scope), the allowed dimensions and the mandatory filters.
- It specifies grain (per-order, per-day, per-user) and an as-of rule (event time vs processed time).
- It composes: base metrics (revenue) feed derived metrics (revenue per user) and KPIs (vs target).
- Tests assert known values, null behavior, and grain stability on every change.
- Versioning stores the definition history, and the catalog records owner and certification.
A composable metric definition.
In production
- A metrics catalog defines revenue once; finance, sales ops and exec dashboards all reference it, and a change is versioned with a reviewer.
- A KPI library composes base metrics into retention cohorts and weekly targets without duplicating base calculations.
- CI tests validate the metric against a fixture dataset on every merge, so a 'quick edit' can't silently change headline numbers.
Best practices
- Write definitions as data (name, formula, scope, owner), not as prose to be re-implemented.
- Version every change and require a test that asserts a known value.
- Compose from base metrics; avoid re-deriving a base metric inside a KPI.
- Document as-of timing and currency/timezone assumptions in the definition.
Common mistakes
- Copy-pasting metric expressions into each report 'temporarily' — the permanent fork.
- Versioning the dashboard but not the metric, so rollbacks are impossible.
- No tests: a renamed column silently changes a headline number.
- Defining metrics in tools that can't be version-committed (some GUI-only setups).
Common issues
Headline revenue changed after a 'refactor'A shared definition was edited without tests catching the filter change
Require review + a known-value test on every semantic definition change.
New dashboard can't compose existing metricsDefinitions hard-coded dimensions/filters inside formulas
Parameterize by dimensions and filters so metrics compose.
Debugging tips
- When a metric moves unexpectedly, diff the definition history first, then the data.
- Test at the seam: assert the metric against a tiny fixture where you know the answer.
- Check composability — if a KPI doubled because it recomputed a base metric with a new filter, that's the bug.
Interview checkpoint
Quick quiz
Which practice best prevents metric definitions from forking across teams?
A composite KPI should re-derive its base metric every time to stay 'fresh'.