One definition per metric: building a semantic layer people trust

When two dashboards disagree about revenue, the data is rarely at fault. The calculation usually lives in several places, and a semantic layer fixes that only if its definitions are owned, tested and versioned the way code is.

By Nabil Ahmed8 minute read

The lunar surface near 4°S, 71°E, lit by a low Sun with night falling across one side.
The Moon near 4°S, 71°E. Rendered by Farside from NASA Lunar Reconnaissance Orbiter elevation data.

A familiar monthly meeting opens with finance and sales each holding a different figure for last month's revenue, and the first twenty minutes are spent working out which of them is right. Usually both are correct, because they answer slightly different questions, but no one ever wrote down which question each figure was meant to answer.

The cause lies in how the calculation is spread around the organization. Revenue is computed in a finance report, in three dashboards, in a spreadsheet that someone exports every Monday and in a SQL snippet that analysts paste to one another. Each of those copies was correct when it was written and each has drifted since then. Cleaning the data does nothing for this problem, since the data is the same in every case and what differs is the logic applied to it.

We think a metric should be defined once, in one place, with everything that displays the metric reading that single definition. Which tool holds the definition matters less than the discipline around it, because a semantic layer without owners soon becomes one more place where the logic can drift, and so does one that lacks tests or a change process.

In brief

  • Conflicting numbers usually come from the same calculation being written several times over, and much less often from bad source data.
  • A semantic layer is a single, versioned place where metrics, dimensions and joins are defined once and then served to every reporting tool.
  • Each metric needs a named business owner, a written definition in plain language, and automated tests that compare it with a figure the business already trusts.
  • Ratios and distinct counts must be defined from their components, because they cannot be added up or averaged across groups.
  • The work should start with the ten or so metrics that executives argue about, and a catalog of everything can wait until those are settled.

What a semantic layer is, and what it is not

A semantic layer is the part of the data stack that translates tables and columns into business terms. It holds the definition of each metric (how it is calculated), of each dimension (how the metric can be sliced) and of the joins between them, so that when a consuming tool asks for "net revenue by region" it gets the same answer every time.

Several kinds of product can do this job. Some BI tools carry their own modeling layer (LookML in Looker, semantic models in Power BI), while others such as the dbt Semantic Layer or Cube sit between the warehouse and any consumer. That choice decides how many tools can share the definitions, which matters more than any comparison of feature lists. A definition held inside one BI tool is still a single definition, although only for the people who use that tool, and the notebook, the planning spreadsheet and the AI assistant that writes SQL will each go on to invent a version of their own.

A semantic layer does not replace the data warehouse. It assumes there are clean, modeled tables underneath it, with facts at a known grain, conformed dimensions and history that has been handled deliberately. If the orders table contains duplicates, the semantic layer will consistently serve the same wrong number, which is why the warehouse model needs to be right before definitions are placed on top of it.

A glossary is also something different. It describes what a term means, whereas the semantic layer actually executes the calculation, and the two ought to agree. The easiest way to keep them in agreement is to generate the glossary from the layer.

Why definitions drift

Most drift comes from three mechanisms, and it is worth naming each of them because each one needs a different safeguard.

Filters that live in the report. The sales dashboard's "revenue" leaves out internal test accounts because someone added a filter two years ago, while the finance report includes them, and by now whoever added the filter has probably forgotten it exists.

Different grains and different clocks. One team counts an order when it is booked, another counts it when it ships, and a third counts it when the invoice goes out. Each of these is a legitimate metric, and the mistake lies in giving all three the same name.

Aggregating things that do not aggregate. Averaging a margin percentage across regions does not give the company margin, and adding up twelve monthly counts of distinct customers does not give the number of distinct customers for the year. Errors of this kind raise no warnings and can persist for years inside spreadsheets.

A well-built layer deals with the third mechanism through the way it stores metrics. A ratio is kept as a numerator and a denominator, and the division is done after aggregation at whatever level the user asks for. A distinct count is declared as one, so that the engine recomputes it for each grouping where a spreadsheet would have summed it.

Three net revenues

Take a mid-size distributor that runs an ERP, a CRM and a cloud warehouse, where leadership is shown three different figures for monthly net revenue. When someone investigates, they find the following.

Source What it actually computes
Finance report Invoiced amount, less credit notes, less rebates accrued, by invoice date
Sales dashboard Booked order value, less discounts, by order date, excluding two intercompany accounts
Operations dashboard Shipped line value at list price, by ship date

Each of these calculations is valid for what it measures, and the trouble is that three different metrics are sharing a single label. Fixing it takes two decisions, which are to agree which of them carries the name "net revenue" and to give the other two names that describe what they actually compute.

The CFO owns that decision and chooses the finance definition, so the other two become "booked order value" and "shipped value at list". The agreed definition is then written down once in a form that a machine can execute. Its syntax varies from one tool to another, but the content is what matters, and in an illustrative, tool-neutral form it looks like this:

metric: net_revenue
label: Net revenue
owner: finance-controller
description: >
  Invoiced amount less credit notes and accrued rebates,
  recognized on invoice date. Excludes intercompany accounts.
type: sum
expression: invoice_amount - credit_note_amount - rebate_accrued
source: fct_invoice_lines          # grain: one row per invoice line
time_dimension: invoice_date
filters:
  - is_intercompany = false
dimensions: [region, product_family, customer_segment, sales_channel]
tests:
  - reconcile_to: finance_gl_monthly_revenue
    tolerance: 0.5   # currency units per month, rounding only
---
metric: gross_margin_ratio
label: Gross margin
owner: finance-controller
type: ratio
numerator: gross_margin_amount
denominator: net_revenue

Three details in that file do most of the work. The owner field names a role with the authority to approve or reject a change, and the filters block moves the intercompany exclusion out of a dashboard and into the definition, so that every consumer inherits it. The tests block reconciles the metric against the general ledger each time the pipeline runs, which means an upstream change that breaks the number is caught before anyone builds the board pack.

After that, the sales dashboard is repointed to the layer, and its headline figure changes because it had been showing bookings under the wrong label. The conversation that follows is uncomfortable but necessary, and it is far better to have it once and deliberately than to repeat it in a meeting every month.

How to build it, in order

  1. List the contested metrics. Ask the executive team which numbers they have argued about over the last two quarters. The list tends to be short, typically covering revenue, margin, active customers, order backlog, on-time delivery and headcount, and that is where to begin, because ten metrics people trust are worth more than four hundred unreviewed ones.
  2. Find every existing version. For each metric, gather the reports, dashboards and spreadsheets that compute it and write out what each of them really does, in the way the table above does. This is slow detective work, but it is also the step where most of the value turns up.
  3. Decide, and name the owner. Every metric gets one business owner, a definition in plain language and a decision about what the alternative versions will be called. That decision belongs to governance more than to engineering, and it sits with whoever is accountable for the number. Our data strategy and governance work treats metric ownership as part of the same structure as data ownership, since a metric owner needs to know who owns the tables beneath the metric. A data contract on those tables then stops the inputs from changing without notice.
  4. Encode the definitions and test them. Write the definitions into the layer and keep them in a repository where every change is reviewed. Add reconciliation tests against a figure the business already trusts (the ledger or a statutory report), and add tests for the cases that do not add up, for example a check that the company-level ratio equals the total numerator divided by the total denominator. A failing test should stop the publish step, for the reason given in pipelines that fail loudly, which is that a missing number makes people ask a question while a wrong number leads them to make a decision on it.
  5. Repoint consumers and retire the copies. A definition has changed nothing until the reports people use actually read it. Move the dashboards that matter onto the layer and mark them as certified, and remove the old ones or label them clearly, because if both versions stay in place the argument will carry on.
  6. Run a change process. Definitions will change when a new rebate scheme arrives, when the company makes an acquisition or when regions are reorganized. Each change goes through a pull request that the owner approves, with a note on whether history is restated, and the old version should stay queryable for a period under an explicit name so that year-on-year comparisons can still be explained.

Where a semantic layer does not help

A semantic layer will not settle a disagreement about what the business ought to measure. If sales and finance cannot agree on when revenue counts, the layer will give you two clearly named metrics, and reaching agreement remains a job for the people involved.

It also adds a dependency, since every dashboard now relies on the layer being available and fast. You should plan for caching or pre-aggregation of the heavier metrics and run the layer as a production system that has monitoring and an on-call path.

The layer can turn into a bottleneck as well. When every new dimension requires a ticket to a central team, analysts start to work around it and the drift comes back. A better arrangement lets domain analysts contribute definitions through review while a small central group owns the standards and the shared metrics, and we discuss the organizational side of this in why self-service analytics fails.

Finally, a semantic layer is no substitute for sound modeling underneath it. Complicated logic belongs in tested warehouse transformations, and the layer should mostly aggregate and slice facts that are already clean, without trying to reconstruct them.

What to do next

A useful first month would cover the following steps:

  • Ask the leadership team for the five to ten numbers they have disputed recently, and rank them by how much decision-making depends on each.
  • For the top three, trace every place where the figure is calculated and write down the actual logic of each version.
  • Assign a named owner to each metric and get a written definition in plain language signed off.
  • Before you buy another tool, check whether the ones you have already include a modeling layer you are underusing, keeping in mind that the deciding question is how many consuming tools need to share the definitions.
  • Encode the first three metrics with a reconciliation test against a trusted figure. Once that passes, repoint one executive dashboard and retire the version it replaces.
  • Agree how a definition gets changed, and who approves the change, before the first change request arrives.

This is how we approach business intelligence and analytics, and we judge the work a success when the meeting starts with one number and the time goes on deciding what to do about it.

Related services

Start a conversation.

A short paragraph is enough. A principal reads every message and replies within one working day.

Or email hello@farside.works. We use what you send only to reply. Privacy