THIS EXPLANATION
THE ROOM
CDA·232 Computing, Data & AI 6 MIN · 8 STATIONS

The semantic layer

A Socratic walk-through of the semantic layer — reasoned out one step at a time, not lectured.

abcdefgh
a

The question we started with

THE QUESTION #

Why do two dashboards built from the same warehouse disagree about revenue?

Two dashboards. One warehouse. Both say "Revenue, last quarter". One says 4.21 million, the other 4.06 million. Nobody has made an error, nobody is using stale data, and both queries can be shown to be correct against the tables they read.

This is the most common failure in analytics, and the first reaction is almost always the wrong one: to go looking for the bug. There is no bug. So what is actually different between the two, if the data is identical and the code is correct?

b

Reasoning it through

REASONING #

Write out what a revenue query has to decide. It must choose whether to count an order at the moment it was placed or the moment it was paid. It must decide whether refunds are subtracted, and whether they are subtracted from the quarter they were issued in or the quarter of the original sale. It must decide about tax, about shipping charged to the customer, about discounts, about test orders from the internal QA account, about orders from a subsidiary that reports separately, and about how a foreign currency was converted — at the day's rate or the quarter's average.

Now count the possible answers. Even with a dozen binary choices, there are thousands of internally consistent things "revenue last quarter" could mean. Both dashboards picked one. They picked differently.

Notice where the divergence actually lives. Not in the data, and not in the SQL as a matter of correctness — in the definition, which was never written down anywhere and so was re-decided, independently, by each person who needed it. And ask a sharper question: when the first analyst wrote their query, where were they supposed to look up the agreed answer? There was nowhere. The definition had no home, so it was reconstructed from scratch each time.

That reframes the problem. This is not a data quality issue and not an analyst competence issue. It is a coordination problem: many people need the same non-obvious decision, and there is no artefact that carries it.

So consider the obvious fix — write it down in a document. Does it work? Partially, and it is worth being clear about why only partially. A document is not consulted at the moment of writing SQL, it cannot be tested, and it drifts silently from the queries people actually run. Within a year you have a wiki page that describes a definition nobody uses, and you have not eliminated the divergence, only added a fourth opinion.

What would fix it properly? The definition must sit somewhere that queries cannot bypass. If revenue exists as a defined, versioned object — with its measure, its grain, its filters, its time basis, its currency rule — and every dashboard requests that object rather than writing its own arithmetic, then there is exactly one place the answer can come from. Change it once and every consumer changes together. Disagreement stops being possible rather than merely discouraged.

That is what a semantic layer is: the place where business definitions live, between the physical tables and the tools people use. Its ancestor is the business-object layer of tools like BusinessObjects in the 1990s; its familiar modern form is Looker's LookML, and more recently standalone metric layers such as Cube and dbt's MetricFlow that aim to serve one definition to many front-end tools.

There is a second thing it buys, less discussed but real. A defined metric knows which dimensions it may legitimately be sliced by. Revenue defined at order grain cannot honestly be broken down by individual product line if an order contains several products — and a layer that knows the grain can refuse that request instead of returning a plausible wrong number.

c

The analogy

THE ANALOGY #
THE FIGURE

Think of a laboratory that measures the length of a component. Ten technicians with ten rulers will produce ten slightly different numbers, and every one of them will have measured carefully. The fix is not to retrain the technicians or to write a memo about diligence — it is a single calibrated master gauge that every ruler is checked against, kept in one place, under one person's control, with a record of when it changed. The technicians keep their own rulers and their own judgement; what they no longer keep is a private opinion about what a millimetre is.

WHERE IT BREAKS DOWN

a metre has an external, physical definition that the master gauge merely approximates, whereas "revenue" has no external truth at all — the semantic layer does not discover the right definition, it merely makes one definition binding, and choosing it remains an argument for humans to have.

d

Clarifying the model

THE MODEL #

The most important correction is that one. A semantic layer resolves disagreement, not doubt. It cannot tell you whether refunds should net against the original quarter; it can only guarantee that once someone with authority decides, everyone gets the same answer. Installing the technology without settling the definitions produces a well-engineered layer that serves an arbitrary choice with great consistency.

A related misconception is that a single definition per metric is always the goal. Finance's revenue, recognised under an accounting standard, genuinely is a different quantity from the sales team's bookings, and forcing them into one number destroys information. The layer's real job is to make each definition explicit, named distinctly, and separately governed — not to collapse them. Two numbers with two names is a healthy state; two numbers with one name is the disease.

Two practical notes. A semantic layer only helps consumers who go through it — the moment one team connects a spreadsheet directly to the warehouse, that team is outside the guarantee. And defining metrics centrally does not mean defining them by one team: the durable arrangements let the domain that owns the data own its metric definitions, with the layer providing the mechanism rather than the authority.

e

A picture of it

THE PICTURE #
The semantic layer
The semantic layer Read the arrows as "depends on". The whole argument is visible in which arrows terminate where: the dashboard and the notebook both point at one metric definition, so they cannot disagree, while the direct-SQL box points straight at the physical table and is therefore outside the guarantee entirely -- that box is not an error in the design, it is the honest depiction of the leak every real deployment has. Inside the metric class, notice that the fields are all the decisions we enumerated earlier, and the two methods are the second benefit: a definition that knows its own grain can refuse a breakdown that would be meaningless. The self-association is how a ratio such as margin is built from other defined metrics rather than from raw columns. {"generator":"[email protected]","source":"../Socrates/.diagram-cache/_src/the-semantic-layer.md","sourceIndex":1,"sourceLine":4,"sourceHash":"db2e95cf94cf5b93a96d886dfe7d2080c491aa811a635273aa4a24b82e23cbee","diagramType":"class","layoutVariant":"source","repairedDuplicateIds":[],"motion":"entrance-with-reduced-motion-fallback","presentation":"editorial","attempt":1,"viewBox":{"x":0,"y":0,"width":902,"height":1000},"qa":{"passed":true,"findings":[]}} compiles down to resolves through resolves through bypasses the definition may compose into ratios MetricDefinition +name +measure +grain +time_basis +filters +currency_rule +owner +version allowedDimensions() rejectIncompatibleSlice() WarehouseTable +physical_columns +partitioning Dashboard +requests_metric_by_name NotebookQuery +requests_metric_by_name DirectSQL +writes_its_own_arithmetic

How to readRead the arrows as "depends on". The whole argument is visible in which arrows terminate where: the dashboard and the notebook both point at one metric definition, so they cannot disagree, while the direct-SQL box points straight at the physical table and is therefore outside the guarantee entirely — that box is not an error in the design, it is the honest depiction of the leak every real deployment has. Inside the metric class, notice that the fields are all the decisions we enumerated earlier, and the two methods are the second benefit: a definition that knows its own grain can refuse a breakdown that would be meaningless. The self-association is how a ratio such as margin is built from other defined metrics rather than from raw columns.

f

What became clearer

WHAT CLEARED #
WHAT CLEARED

The two dashboards disagreed because "revenue" is a dozen unrecorded decisions, and nothing in the warehouse held them. A semantic layer is not a technology for making numbers correct — it is a place for a definition to live where queries must pass through it, converting an argument that would otherwise be re-litigated silently in every query into one that is had once, recorded, versioned and owned.

g

Where to go next

ONWARD #
  • How metric definitions are tested, and what a regression test for a business definition even looks like.
  • Why serving one definition to many BI tools is harder than it sounds, and what a query interface must expose.
  • The governance question underneath it: who is allowed to change what revenue means, and how consumers learn that it changed.
h

Key terms

TERMS #
TermWhat it means
Semantic layera layer between physical tables and analytics tools where business definitions are declared, versioned and served.
Metric definitionthe full specification of a measure: its aggregation, its grain, its filters, its time basis and its currency handling.
Grainthe level of detail one row represents, which determines which breakdowns of a metric are legitimate.
Headless BIa semantic layer that serves definitions to multiple front-end tools rather than being tied to one.
Single source of truththe property that a named quantity has exactly one authoritative definition, not merely one storage location.

Every term the collection defines is gathered in the glossary.

Nearby on the shelf

4