Level 2: AI layer

One governed place

Metric contracts as code: one definition, many consumers.

Guide 5's contract says what a number means. This piece puts it where every consumer, a report, a subscription, an AI tool, gets the same value and the same answer status.

Updated November 2026Example data, not from a client.
On this page
  1. The contract is the spec
  2. Put it in one governed place
  3. Return a status with the value
  4. Every consumer, same answer
  5. What I check

Guide 5 argued that self-service needs a contract, not a license: a one-page statement of what a number means, which date it uses, and what it does when data is missing. A contract on a wiki page is a good start. It's also easy to ignore, because the formula people actually run lives somewhere else.

The fix is to put the contract where the number is computed, once, and have every consumer read it from there.

The contract is the spec

Here's the contract for the example's main metric. Every line came from a signed concept card in part 1:

Contract · Net Revenue (reporting date) v1.0
FieldValue
DefinitionSUM(amount) over Revenue, adjustments included
Date rulereporting_date
Periodrequired; end date exclusive; no default
Neversum Terms amount as revenue
StatusesCOMPLETE · NO_RECORDS_IN_PERIOD · NO_MATCHED_RECORDS · INCOMPLETE_UNKNOWN_PERIOD · INCOMPLETE_AMOUNT
ReferenceC-001, P-01, April 2025 = 100.00 (COMPLETE)
Ownernamed in the concept card

Example data, not from a client.

Two lines matter most for AI. Period: required, no default means “revenue for all time” isn't a question this metric answers. Statuses means the metric says what kind of answer it's giving, not just a value.

Put it in one governed place

Diagram · Metric contracts as code: one definition, many consumers

Metric contracts as code: one definition, many consumers A contract box for Net Revenue by reporting date, version 1.0: the definition is SUM of amount over Revenue, the date rule is reporting_date, a period is required with an exclusive end date, Terms amount is never summed as revenue, three empty-case statuses, and the reference answer April 2025 equals 100.00. Arrows fan out to four consumers: a report on a certified model, a Pulse metric or subscription, Copilot or a data agent, and a notebook or API. Each gets the same value and the same status. Three status chips: COMPLETE with 100.00 for April 2025; NO_RECORDS_IN_PERIOD for July 2025, which has no rows; INCOMPLETE_UNKNOWN_PERIOD, withheld when a row has no date. Net Revenue (reporting date) · contract v1.0 Definition SUM(amount) over Revenue Date rule reporting_date Period required, end date exclusive Never sum Terms amount as revenue Empty cases three statuses, below Reference April 2025 = 100.00 same value + same status Report certified model Pulse / subscription metric definition Copilot / data agent reads the measure Notebook / API semantic layer API ANSWER STATUS TRAVELS WITH THE VALUE COMPLETE April 2025 100.00 NO_RECORDS_IN_PERIOD July 2025 no rows INCOMPLETE_UNKNOWN_PERIOD a row has no date withheld Example data, not from a client.
The contract lives in one governed place. Every consumer gets the same value and the same answer status, so a tool can say “withheld” instead of guessing. Example data, not from a client. Open full size

Each platform has a place where a metric is defined once:

  • dbt. Simple metrics are declared in YAML on a semantic model and served to tools through the Semantic Layer APIs.
  • Power BI. A measure in one shared semantic model. Report authors get Build permission to create their own reports on it, but no edit role on its workspace, so they can't change the official measure. Certification tells people it's the reviewed one. It's a trust signal, not a lock.
  • Tableau. A Pulse metric definition holds the measure, its time dimension and the dimensions viewers can filter by, as the source of truth for every metric built on it.
  • Fabric IQ ontology Preview. It can be generated from a Power BI semantic model. Measures come across as metrics, and the semantic model stays the owner of the DAX expression. Generating one needs Read and Build permission on the model.

In the dbt version of the example, the two metrics from the contract look like this. They sit under the revenue semantic model from part 2:

    metrics:
      - name: net_revenue
        label: Net Revenue (reporting date)
        description: >-
          Recognized revenue including
          adjustments, by reporting date.
        type: simple
        agg: sum
        expr: amount
      - name: net_revenue_accounting
        label: Net Revenue (accounting date)
        type: simple
        agg: sum
        expr: amount
        agg_time_dimension: accounting_date

Asked for April 2025 through MetricFlow, net_revenue returns 100.00 and net_revenue_accounting returns -20.00, the same answers as guide 1. Two dates, two named metrics, no guessing which one “revenue” meant.

Then delete or hide every other copy. A contract in one place and three unofficial formulas elsewhere is still four definitions.

Return a status with the value

A plain metric returns a number or a blank, and a blank can mean several things. The contract's statuses split them. Here's the status logic as SQL, so you can see every case:

WITH scope AS (
  SELECT * FROM revenue
   WHERE customer = 'C-001'
     AND product = 'P-01'
), d AS (
  SELECT COUNT(*) AS scope_rows,
    COALESCE(SUM(CASE
      WHEN reporting_date IS NULL
      THEN 1 ELSE 0 END), 0)
      AS unknown_date_rows,
    COALESCE(SUM(CASE
      WHEN reporting_date >= '2025-04-01'
       AND reporting_date < '2025-05-01'
       AND amount IS NULL
      THEN 1 ELSE 0 END), 0)
      AS missing_amount_rows,
    COALESCE(SUM(CASE
      WHEN reporting_date >= '2025-04-01'
       AND reporting_date < '2025-05-01'
      THEN 1 ELSE 0 END), 0)
      AS period_rows,
    SUM(CASE
      WHEN reporting_date >= '2025-04-01'
       AND reporting_date < '2025-05-01'
      THEN amount END) AS subtotal
  FROM scope
)
SELECT CASE
    WHEN scope_rows = 0
      THEN 'NO_MATCHED_RECORDS'
    WHEN unknown_date_rows > 0
      THEN 'INCOMPLETE_UNKNOWN_PERIOD'
    WHEN missing_amount_rows > 0
      THEN 'INCOMPLETE_AMOUNT'
    WHEN period_rows = 0
      THEN 'NO_RECORDS_IN_PERIOD'
    ELSE 'COMPLETE' END AS answer_status,
  CASE WHEN scope_rows > 0
        AND unknown_date_rows = 0
        AND missing_amount_rows = 0
        AND period_rows > 0
       THEN subtotal END AS value
FROM d;
Result
answer_statusvalue
COMPLETE100.00

Result on the example. Example data, not from a client.

I ran it on the example for each case. April returns COMPLETE with 100.00. July returns NO_RECORDS_IN_PERIOD with no value. Customer C-999, who has no rows at all, returns NO_MATCHED_RECORDS instead of falling through to a misleading “complete.” Add an April row with no date and the answer becomes INCOMPLETE_UNKNOWN_PERIOD, with the value withheld. A row with no amount gets INCOMPLETE_AMOUNT.

The value is withheld, not just flagged. That matters for AI. A tool that receives 100.00 next to “withheld” can easily repeat the 100.00. A tool that receives no number and a status can only say why it can't answer.

Every consumer, same answer

The test of a contract is simple. Ask the reference question, C-001, P-01, April 2025, through every consumer you have: the certified report, the subscription, the notebook, the AI tool. Each one should return 100.00 and COMPLETE. Any that doesn't is reading a copy, or applying its own date.

I keep that reference question in the test suite from guide 7, so the check runs every time the model changes, not just on launch day.

What I check before a metric goes to AI

  1. Is the metric defined in exactly one governed place, with every copy removed or hidden?
  2. Does it require a period instead of defaulting to all time?
  3. Does it return a status, and withhold the value when the data is incomplete?
  4. Does every consumer return the reference answer: 100.00, COMPLETE?

One definition. Every consumer reads it.

About to put AI on a Power BI model?

I review one model, fixed scope, and tell you what to fix first.

See the model review

Privacy

Related