Metrics and KPI definitions
A metric is a KPI written down once: what is counted or summed, over which object type, sliced by what, filtered how and rolled up over which periods. The definition lives in the Ontology registry with an owner and a version, and every place that shows the number reads it from there. The waste cost on the operations lead's card, in the Monday briefing, in the monthly report and in the Assistant's answer is one calculation, not four
In the platform today
Metrics run in the platform service today, with definitions for each demo company. Definitions are YAML, in ontology.yaml under metrics: or in a sibling metrics.yaml. Every read runs under the reader's own access: object metrics through the object query engine with the reader's access labels, row policy and hidden properties, SQL metrics through the SQL workspace with the reader's grants. Every value in a request is a bound parameter
metrics:
dispatch-reliability:
name: Dispatch reliability
# an object type, or sql: for a read-only SQL source
over: flight
where: { status: { $in: [Departed, Arrived, Cancelled] } }
value:
ratio: # or sum (a list), difference, product
- { name: clean, count: { where: { delayCode: { $nin: ['41', '42'] } } } }
- { name: operated, count: true }
sliceBy: [aircraftType, origin, route, flight-aircraft.homeBase]
time: { property: scheduledDeparture, grains: [day, week, month] }
windows: [7d, 28d]
compare: [previous, sameLastYear]
format: { style: percent, decimals: 1 }
better: higher
target: { value: 0.985, label: Plan 98.5% }
owner: group:maintenance-control
status: Certified
version: 2
changeNote: Cancellations count against dispatch reliability
{ "group": ["origin"], "where": { "aircraftType": "DH8-400" },
"time": { "grain": "week", "last": 2 }, "compare": "previous" }
{
"metric": { "id": "dispatch-reliability", "version": 2, "status": "Certified",
"certified": true,
"target": { "value": 0.985, "label": "Plan 98.5%" } },
"time": { "grain": "week", "from": "2026-10-12T00:00:00-03:00",
"to": "2026-10-26T00:00:00-03:00", "timezone": "America/Halifax" },
"accessLabels": [],
"groups": [
{ "key": { "period": "2026-10-19", "origin": "YHZ" }, "value": 0.9649,
"inputs": { "clean": 110, "operated": 114 }, "partial": true,
"previous": 0.9732, "change": -0.0083 }
]
}
| Part | In the platform service |
|---|---|
| Values | count, sum, avg, min, max, countDistinct and percentile, composed with ratio, sum, difference and product, up to 4 levels, inputs pinned with id@version |
| Sources | An object type, or a read-only SQL statement over the lake that names its columns |
| Slices | Properties, derived values and properties one link away, up to 3 per read |
| Time | Grains from hour to year, rolling windows up to 400 days, previous, sameLastYear and fixed offsets such as -7d. Calendar periods in the ontology's time zone, weeks start on Monday, partial periods flagged and compared at the same elapsed time |
| Versions | Each definition is recorded the first time it is seen, so id@version reads an earlier version and a calculation change without a new version number is reported |
| Certification | From the catalogue, the same certified and deprecated statuses as datasets and object types |
| Endpoints | GET /api/v2/metrics, GET /api/v2/metrics/{id} and /versions, POST /api/v2/metrics/{id}:query, :explain for the compiled statement without running it, and {"metric": id} on POST /api/v2/query/aggregate |
| Dashboards | Tiles over metrics, objects, SQL and text, on dashboards |
Delivered on request: the TypeScript defineMetric form, metric cards on screens other than Dashboards, the result cache, scheduled snapshots, acrossTime for balances, season grains from a tenant calendar, slices more than one link away, and the side-by-side review of a calculation change. The rest of this page is delivered on request
Why define a KPI once
In most plants the same KPI has several homes. Fill rate lives in a spreadsheet the customer service lead keeps, in a query behind the wholesale dashboard and in a cell of the board pack, and the three disagree because one counts cancelled lines, one excludes the online store and one uses ship date instead of promise date. Nobody is wrong. Each copy was right for the person who wrote it, and nobody wrote down which one is the company's
A metric definition settles that. It states the calculation in terms of the Ontology, so it reads the same Order line and Production batch objects that every screen already uses, under the same permissions. It has an owner who decides what the number means and a version history that shows when that meaning changed. Every consumer refers to the definition by name instead of copying its logic, so changing the definition changes the number everywhere at once, with a record of who changed it and why
How a metric is computed
A metric is not a stored number. It is a recipe that the object query service turns into an aggregation at read time, for a particular reader, slice and period. The registry holds the definition; the query service compiles it into the same plan a hand-written aggregation would produce, runs it where the data lives and returns the value with a reference to the definition revision and the read version it used
Because the calculation runs under the reader's access, two people can see different values for the same metric. A shift lead whose row policy shows only their own shop gets the scoopers scheduled at SHP-HFX when they ask for "scoopers scheduled by shop"; the operations lead gets every shop. That is the same rule that applies to derived properties: a metric never reveals more than the objects it was computed from
Key terms
| Term | What it means | Example |
|---|---|---|
| Metric | A named, versioned KPI definition in the registry | waste-per-litre, "Waste cost per litre" |
| Over | The object type the metric is computed from. One per metric | Waste record |
| Value | What is computed for each group of objects: a count, sum, average, minimum, maximum, distinct count, percentile or a ratio of other metrics | Sum of litres |
| Filter | Conditions that always apply. A reader can narrow them but never widen them | Exclude records with cause Short-dated returns |
| Slice | A property, or a property reached through a link, that the value can be broken down by | Line, product, shop, crossing |
| Time property | The date or time that places each object in a period | date |
| Grain | The periods the metric can be rolled up to | Day, week, month, quarter, season |
| Window | A rolling period ending at each point in time | Trailing 7 days, trailing 28 days |
| Comparison | The same metric for an earlier period, with the change | Previous week, same week last season |
| Composed metric | A metric whose value is built from other metrics | Waste cost per litre = waste cost / wasted litres |
| Revision | One immutable saved state of a definition. The version number changes only when the number would change | waste-per-litre@3 |
| Status | Draft, Certified or Deprecated | Certified by Operations |
Defining a metric
Built definitions are YAML, shown above. On request, the same definition in TypeScript or from a form on the Dashboards screen
Composed metrics pin the exact versions of their inputs with id@version. Ratios and other composed values are always computed from the aggregated inputs of each group, never as an average of per-object ratios. Waste cost per litre for Line 2 last week is total waste cost over total wasted litres for Line 2 last week, so a 5 L spill of costly mix does not weigh as much as a 200 L changeover flush
Time, windows and comparisons
Every metric with a time property can be read at any of its grains, in a rolling window, and against an earlier period. The time zone and the first day of the week come from the definition, defaulting to the tenant's settings, so a "week" means the same seven days on every screen
| Setting | Options | Default |
|---|---|---|
| Grains | hour, day, week, month, quarter, year, and named periods from the tenant calendar such as season | day, week, month |
| Rolling windows | Any whole number of hours or days up to 400 days, e.g. 24h, 7d, 28d, 364d | None |
| Comparisons | previous (the period before), sameLastYear, sameLastSeason, or a fixed offset such as -7d | previous |
| Across time | sum for flows, first, last, min, max or avg for balances | sum |
| Incomplete periods | show with a partial flag, or hide | show, flagged |
| Empty periods | zero or null | zero for counts and sums, null for ratios |
Comparisons align by calendar position, not by elapsed time. "Same week last season" for the week of 13 July compares with the matching week of the previous season in the tenant calendar, which matters for a business whose Saturdays in July sell five times what its Saturdays in May do. A comparison of an incomplete period is cut to the same elapsed time: Thursday at 15:00 compares with the previous week up to Thursday at 15:00
Where metrics are used
Any surface that shows a KPI refers to a metric by id, optionally pinned to a version. None of them can define a calculation of its own; a card that needs a different number needs a different metric
| Surface | How it refers to the metric | Version used |
|---|---|---|
| Operations view cards | A card names a metric, a slice, a grain or window and optionally a comparison | Latest published, unless the card pins one |
| Briefings | A briefing section lists metrics with the period it covers; the text around them is templated | Latest published at the time the briefing runs, recorded in it |
| Reports | Each table or chart cell names a metric and its slice | Pinned when the report is published, so a reissued report reproduces its numbers |
| Assistant | Business terms map to metrics, and verified answers name the metric they return | Latest certified; see how the Assistant answers |
| Agents and functions | An aggregate tool given a metric id, or mso.metrics(id).read({...}) in the SDK | Pinned in the agent or function version |
| REST API | A metric reference in POST /query/aggregate | Latest published, or id@version |
Reading a metric through the API
A metric reference replaces the query and measure of a plain aggregation. The caller can add filters, which narrow the metric's own filter, and choose slices from those the metric offers. A slice it does not offer fails with INVALID_ARGUMENT
{
"metric": "waste-per-litre",
"where": { "area": { "$in": ["Line 1", "Line 2"] } },
"group": [{ "by": "area" }],
"time": { "grain": "week", "from": "2026-09-28", "to": "2026-10-25" },
"compare": "previous",
"include": ["inputs", "objectSet"]
}
{
"metric": { "id": "waste-per-litre", "version": 3, "status": "CERTIFIED" },
"exact": true,
"readVersion": "rv_000000000183F2A1",
"groups": [
{ "key": { "area": "Line 1", "week": "2026-10-19" },
"value": 2.14, "previous": 2.13, "partial": false,
"inputs": { "waste-cost": 300, "wasted-litres": 140 },
"objectSet": "os_01JB2S0K8F" },
{ "key": { "area": "Line 2", "week": "2026-10-19" },
"value": 2.14, "previous": null, "partial": false,
"inputs": { "waste-cost": 450, "wasted-litres": 210 },
"objectSet": "os_01JB2S0K9M" }
]
}
The objectSet handle is a saved object set of exactly the objects behind that value, readable for 60 minutes with POST /query. It is how a card, a briefing or an Assistant answer opens "the 2 waste records behind Line 2's $2.14 a litre". The SDK makes the same call like this
mso.metrics("waste-per-litre").read({
group: ["area"],
time: { grain: "week", last: 4 },
compare: "previous"
})
From a card to its definition
Every card that shows a metric has a "How is this calculated" link. It opens the definition page, which shows, in this order:
- The number in words. A sentence generated from the definition, for example "Waste cost divided by litres wasted, for product and milk thrown away in the plant and the shops, by week starting Monday in Atlantic time"
- Status and owner. Certified or not, who owns it, who certified it and when
- The objects. The object set behind the value on the card that was clicked, with the reader's access, ready to sort and open
- The definition. The definition, with the inputs of a composed metric linked to their own pages
- History. Every revision with its change note and a chart of the metric computed under the old and new definitions side by side
- Where it is used. Every card, briefing, report, verified answer, agent and function version that refers to it, with the version each one reads
Versions, ownership and review
A metric belongs to one owner, a group, and has one steward, the person who answers questions about it. Editors on the owning project can draft changes; only the owner group can publish them. Every save creates an immutable revision in the registry, and the registry decides whether that revision changes the number
| Change | Kind | Effect |
|---|---|---|
| Name, description, format, target, steward | Display | New revision, same version. Applies everywhere at once |
| Add a slice, a grain, a window or a comparison | Additive | New revision, same version. Existing uses are unaffected |
| Value, filter, object type, time property, across-time rule, input versions | Calculation | New version. Needs a change note and a review by the owner group; composed metrics that use it are offered the update |
| Remove a slice or a grain | Breaking | New version. Refused while any card, report or verified answer uses the slice, and the refusal lists them |
On request, a calculation change is reviewed with numbers, not only with a diff. The review shows the old and new versions computed side by side at each grain the metric offers, the largest differences by slice, and the test questions in the Assistant that return the metric, rerun under the new version. Publishing a new version writes an entry to the audit log and adds a marker on every chart of the metric at the moment the definition changed, so a step in the line is never mistaken for a step in the plant
Certification
A metric starts as a Draft. The owner group can certify a published version, which states that it is the company's number for that KPI. Certification is per version: a new calculation version starts uncertified and keeps showing the previous certified version on surfaces that require certification until it is certified in turn. Deprecating a metric names its replacement, adds a banner to every card that uses it and stops the Assistant from offering it. The full rules for certified and deprecated status, which also apply to datasets and reports, are on certified and deprecated data
| Status | Shown as | Operations view | Assistant |
|---|---|---|---|
| Draft | A grey "Draft" tag | Only on cards in personal or draft views | Used only when a verified answer names it, and labelled Draft |
| Certified | A green tick with the certifying group | Any card | Preferred whenever a business term matches more than one metric |
| Deprecated | A strike-through name and the replacement | Existing cards keep working with a banner, then show the replacement | Not offered; answers point to the replacement |
Finance and Operations both had a "waste" number. Finance's counted the cost in dollars; Operations' counted litres. The registry allows two metrics with similar names but requires distinct ids and, when both are certified, distinct business terms in the Assistant. Here they became wasted-litres ("waste", "scrap litres") and waste-cost ("waste cost", "shrink dollars")
Behaviour and defaults
| Behaviour | Default |
|---|---|
| Result cache | On request, scoped to the metric version, slice, period and the reader's access |
| Freshness | The same as the objects it reads |
| Slices per metric | Properties, derived values and properties one link away; on request, further links away |
| Slices per read | Up to 3, as for any aggregation |
| Composition depth | Up to 4 levels of metrics built from metrics |
| Groups per read | Exact up to 10,000; above that QUERY_TOO_COMPLEX |
| Division by zero | null, shown as "no data", never 0 % or 100 % |
| Access labels | The union of the access labels on every property read. A reader without them gets PERMISSION_DENIED for the metric, not a partial value |
Limitations
- A metric is computed over one object type. Values that need two unrelated types joined on something other than a link need a link type or a derived object type built in a pipeline
- Slices and filters can follow at most 3 links on request, the same bound as any object set query. In the platform service a slice reaches one link away
- SQL is allowed only as a whole read-only source for a metric, run with the reader's grants. Object metrics take no SQL fragments: logic that the measure grammar cannot express belongs in a derived property or a function-backed property that the metric then sums
- Percentiles and distinct counts cannot be inputs to a composed metric, because they do not add across groups
- Distinct counts above 3,000 values per group are approximate, and rolling windows over them are approximate at any size
- Comparisons align only to calendar periods and fixed offsets; comparing with an arbitrary event, such as the week before a recall, needs two reads
- Pinning a card to a version does not stop that version being deprecated; the card shows the deprecation banner like any other
- Metrics read current object state and the object history kept by the object store. Values for periods before an object type existed are not backfilled from source systems