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

Defined onceOne versioned definition per KPI in the registry
Over objectsComputed from an object type, with the reader's access
ComposableRatios and differences of other metrics
TraceableEvery number links to its definition and its objects

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
POST /api/v2/metrics/dispatch-reliability:query
{ "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 }
  ]
}
PartIn the platform service
Valuescount, sum, avg, min, max, countDistinct and percentile, composed with ratio, sum, difference and product, up to 4 levels, inputs pinned with id@version
SourcesAn object type, or a read-only SQL statement over the lake that names its columns
SlicesProperties, derived values and properties one link away, up to 3 per read
TimeGrains 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
VersionsEach 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
CertificationFrom the catalogue, the same certified and deprecated statuses as datasets and object types
EndpointsGET /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
DashboardsTiles 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

Metric definition waste-per-litre, revision 3 value, over, filter slices, time, windows owner, status Ontology registry immutable revisions Object query service Compile to aggregation Apply reader's accessobject, property, access labels Run on objects Operations view cards Briefings and reports Assistant answers POST /query/aggregate Agents and functions Every result carries metric id and revision · read version · the object set behind the number · the access labels of every property it read
Consumers never hold their own copy of the calculation. They hold a reference, and the query service returns the value together with the revision and the objects that produced it

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

TermWhat it meansExample
MetricA named, versioned KPI definition in the registrywaste-per-litre, "Waste cost per litre"
OverThe object type the metric is computed from. One per metricWaste record
ValueWhat is computed for each group of objects: a count, sum, average, minimum, maximum, distinct count, percentile or a ratio of other metricsSum of litres
FilterConditions that always apply. A reader can narrow them but never widen themExclude records with cause Short-dated returns
SliceA property, or a property reached through a link, that the value can be broken down byLine, product, shop, crossing
Time propertyThe date or time that places each object in a perioddate
GrainThe periods the metric can be rolled up toDay, week, month, quarter, season
WindowA rolling period ending at each point in timeTrailing 7 days, trailing 28 days
ComparisonThe same metric for an earlier period, with the changePrevious week, same week last season
Composed metricA metric whose value is built from other metricsWaste cost per litre = waste cost / wasted litres
RevisionOne immutable saved state of a definition. The version number changes only when the number would changewaste-per-litre@3
StatusDraft, Certified or DeprecatedCertified 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

SettingOptionsDefault
Grainshour, day, week, month, quarter, year, and named periods from the tenant calendar such as seasonday, week, month
Rolling windowsAny whole number of hours or days up to 400 days, e.g. 24h, 7d, 28d, 364dNone
Comparisonsprevious (the period before), sameLastYear, sameLastSeason, or a fixed offset such as -7dprevious
Across timesum for flows, first, last, min, max or avg for balancessum
Incomplete periodsshow with a partial flag, or hideshow, flagged
Empty periodszero or nullzero 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

SurfaceHow it refers to the metricVersion used
Operations view cardsA card names a metric, a slice, a grain or window and optionally a comparisonLatest published, unless the card pins one
BriefingsA briefing section lists metrics with the period it covers; the text around them is templatedLatest published at the time the briefing runs, recorded in it
ReportsEach table or chart cell names a metric and its slicePinned when the report is published, so a reissued report reproduces its numbers
AssistantBusiness terms map to metrics, and verified answers name the metric they returnLatest certified; see how the Assistant answers
Agents and functionsAn aggregate tool given a metric id, or mso.metrics(id).read({...}) in the SDKPinned in the agent or function version
REST APIA metric reference in POST /query/aggregateLatest published, or id@version

Reading a metric through the API

POST /api/v2/query/aggregate

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:

  1. 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"
  2. Status and owner. Certified or not, who owns it, who certified it and when
  3. The objects. The object set behind the value on the card that was clicked, with the reader's access, ready to sort and open
  4. The definition. The definition, with the inputs of a composed metric linked to their own pages
  5. History. Every revision with its change note and a chart of the metric computed under the old and new definitions side by side
  6. 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

ChangeKindEffect
Name, description, format, target, stewardDisplayNew revision, same version. Applies everywhere at once
Add a slice, a grain, a window or a comparisonAdditiveNew revision, same version. Existing uses are unaffected
Value, filter, object type, time property, across-time rule, input versionsCalculationNew 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 grainBreakingNew 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

StatusShown asOperations viewAssistant
DraftA grey "Draft" tagOnly on cards in personal or draft viewsUsed only when a verified answer names it, and labelled Draft
CertifiedA green tick with the certifying groupAny cardPreferred whenever a business term matches more than one metric
DeprecatedA strike-through name and the replacementExisting cards keep working with a banner, then show the replacementNot offered; answers point to the replacement
Two metrics with one name

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

BehaviourDefault
Result cacheOn request, scoped to the metric version, slice, period and the reader's access
FreshnessThe same as the objects it reads
Slices per metricProperties, derived values and properties one link away; on request, further links away
Slices per readUp to 3, as for any aggregation
Composition depthUp to 4 levels of metrics built from metrics
Groups per readExact up to 10,000; above that QUERY_TOO_COMPLEX
Division by zeronull, shown as "no data", never 0 % or 100 %
Access labelsThe 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

Related