Metadata, lineage, catalogues and a semantic layer: one definition of revenue for everyone
TL;DR
Difficulty: Advanced
Three numbers called revenue are a metadata problem, not a data problem.
- Write business metadata (meaning, owner, personal data) in the same YAML as the code, and copy it into the warehouse with persist_docs.
- Get lineage from what you already have: the dbt graph and the warehouse's job log. Follow indirect lineage too, because a filter changes a number without being in its formula.
- Keep a short glossary with one owner per term, and use dbt groups and access to make one public model the door into each subject.
- Define net revenue, orders and active customers once in a semantic layer such as MetricFlow, and let every tool ask for them by name.
- A separate catalogue tool can wait until several teams or warehouses make the built in ones too small.
What to read first
One shop, one October, three numbers all called revenue: £143,597, £121,176 and £108,608. Each is right for its own question, and nobody can tell which question that is. This chapter builds the machinery that ends it: metadata written next to the code, lineage down to single columns, a glossary with owners, and a semantic layer that defines every metric once and serves it to every tool.
Three people, three numbers, one word: revenue
It is the first Monday of November at Wrenfield Home, the online homeware shop in Leeds. Priya, the owner, asks a simple question: "What was October's revenue?" She gets three answers.
The shop's own admin screen says £143,597. The marketing spreadsheet, filled from Google Analytics 4 (GA4), says £121,176. The management report Callum, her developer and data engineer, built in the warehouse says £108,608. Nobody made a mistake. Each number is correct for the question it answers. The trouble is that all three are called "revenue", and nobody can see, from the number alone, which question it answers.
This chapter is about the machinery that ends that confusion. It has four parts, and each gets its own sections below:
- Metadata: data about data. What a table means, who owns it, where it came from, when it last loaded.
- Lineage: the map of where every number comes from and where it goes, at the level of tables and of single columns.
- A catalogue and a business glossary: one place where anyone can search for data and read what each word means.
- A semantic layer, also called a metrics layer: one definition of each metric, written once in code and served to every tool, so that "net revenue" means the same thing in the board report, the marketing spreadsheet and the chat assistant.
The earlier chapters built the pieces this one connects. The chapter on cleaning pipelines set up the raw, staging, intermediate and mart layers. The chapter on business rule cleaning wrote the rules that turn raw orders into reportable revenue. The chapter on reporting cleaned data gave every metric a written, versioned definition. This chapter makes those definitions findable, traceable and impossible to drift.
Example: where the three Octobers come from
Here is what each of the three numbers actually counts, using the October 2026 figures from the chapter on business rule cleaning.
| Number | Where it comes from | What it counts | October 2026 |
|---|---|---|---|
| Shop admin "sales" | Solidus, the shop software | Sum of every order total completed in the month by Coordinated Universal Time (UTC), including VAT, delivery, test orders and orders cancelled later | £143,597 |
| Marketing "revenue" | GA4 purchase events | Purchases the browser reported, about 15% fewer than the shop because of consent choices and blockers: 1,683 purchases at £72 | £121,176 |
| Net revenue | The warehouse mart | Completed orders by UK date, minus test and cancelled orders, minus refunds and gift cards sold, without VAT | £108,608 |
The gap between the first and the last is £34,989, which is 24.4% of the admin figure. If Priya compares the admin screen in October with the management report in November, she sees a fall of a quarter that never happened. The fix is not to pick a winner. The fix is to give each number a name, a written definition, an owner and a visible path back to its source. The rest of this chapter shows how.
Metadata is data about your data, and it comes in three kinds
Metadata is everything you know about a table or a column apart from the values inside it. A row in fct_orders says an order was worth £72. The metadata says what "worth" means, in which currency, with or without VAT, who decided that, and when the table was last refreshed.
It helps to sort metadata into three kinds, because each kind is collected differently and serves a different person. Google's own catalogue documentation uses a similar split when it describes indexing "technical structures, business context, data quality metrics, and operational relationships"1.
- Technical metadata describes structure: table and column names, data types, partitioning, the SQL that builds a table, and which tables it reads. Machines produce most of it for free.
- Business metadata describes meaning: what a column means in plain words, which business term it represents, who owns the definition, whether it holds personal data. People must write it, which is why it is usually the part that is missing.
- Operational metadata describes behaviour over time: when a table last loaded, how many rows arrived, how long the job ran, whether the tests passed. Pipelines produce it on every run, and the chapter on observability uses it for monitoring.
Example: the metadata of one column
Take the column net_revenue_ex_vat in Wrenfield's order mart. Here is everything the warehouse and the project know about it, sorted by kind.
| Kind | Fact about net_revenue_ex_vat | Who or what produces it |
|---|---|---|
| Technical | Type NUMERIC, in table analytics_marts.fct_orders, partitioned by completed_date_uk | BigQuery |
| Technical | Built from order_total_gross, refunded_gross, gift_cards_sold_gross and vat_rate | The dbt model's SQL |
| Business | "Order value after refunds and gift cards sold, without VAT, in pounds. Includes delivery." | Callum, in a YAML file |
| Business | Represents the glossary term "net revenue", definition version 4, owner Priya | Callum and Priya, agreed in writing |
| Business | Contains no personal data | Callum, as a tag |
| Operational | Last loaded 5.42am today, 1,980 rows for October, all 11 tests passed | dbt's run results |
Without the business rows, a newcomer would see a number column called net_revenue_ex_vat and guess. With them, nobody has to guess.
You already have more metadata than you think
Before anyone installs a catalogue, it is worth taking stock. A small data platform already produces most of the technical and operational metadata it needs, scattered across a few places.
- The warehouse's information schema. Every SQL database keeps tables about its own tables. In BigQuery,
INFORMATION_SCHEMA.COLUMNSlists every column and type, andINFORMATION_SCHEMA.JOBSlists every query that ran, with the tables it read and the table it wrote2. - dbt's artefacts. Each dbt run writes JSON files into the
target/folder:manifest.jsonholds the full dependency graph, compiled SQL and every description,run_results.jsonholds timings and test results, andcatalog.json, written bydbt docs generate, holds the columns and types as the warehouse sees them3. - The source systems. The Solidus database schema, the GA4 export's documented table layout and the 3PL's file specification are all metadata, even if they live in a vendor's PDF.
What is almost always missing is the business metadata. That is the part to work on first.
Example: Callum's stock take
Callum spends one afternoon counting what Wrenfield already has. The project holds 46 dbt models: 14 in staging, 18 in intermediate and 14 in marts. They have 988 columns between them. The warehouse logs show 22 distinct tables read by the business intelligence (BI) tool in the last 30 days. Every model has its SQL and its dependencies recorded in manifest.json. Only 409 of the 988 columns have a description, and none of them says who owns the meaning.
So the technical lineage exists, the operational history exists, and the meaning is 41% written down. That last number is where the next sections start.
Documentation as code: descriptions live next to the model
The most reliable place for business metadata is the same place as the code that computes the data. If a description sits in a wiki, it drifts the day someone changes the SQL and forgets the wiki. If it sits in the model's YAML file (a plain text configuration format), the same pull request that changes the SQL can change the description, and a reviewer sees both together.
dbt supports this directly. Every model, column, source and metric can carry a description. Long texts can live in docs blocks, Markdown files referenced with the doc() function so one definition can be reused in many places4. The persist_docs setting writes the descriptions into the warehouse itself, as table and column descriptions, so people who query BigQuery directly see them too5. And dbt docs generate builds a browsable documentation site from all of it3.
What a good description says
A useful description answers the questions a careful newcomer would ask. For a table: what one row is (the grain, from the chapter on data modelling), which rows are left out and by which rule, and who owns it. For a number: the unit, the currency, with or without VAT and delivery, which date decides the period, and in which time zone.
Example: the order mart, documented
First, one line in dbt_project.yml turns on persist_docs for every mart, so the descriptions travel into BigQuery:
# dbt_project.yml (extract)
models:
wrenfield:
marts:
+persist_docs:
relation: true
columns: true
Next, the long definition of net revenue goes into a docs block, because the semantic layer, the glossary and the mart will all point to it:
{% docs net_revenue %}
Net revenue (definition version 4, owner: Priya).
Order value after refunds and gift cards sold, without VAT, in pounds.
Includes delivery. Counts completed orders by their UK completion date
(Europe/London). Test, staff and checkout monitor orders and orders
cancelled before dispatch are excluded (rule test_orders v4).
Refunds reduce the month of the original order (order view).
Provisional until 40 days after month end.
{% enddocs %}
Then the model's YAML file describes the table and every column, adds ownership and a personal data flag in meta, and attaches tests:
# models/marts/sales/_sales.yml
models:
- name: fct_orders
description: >
One row per reportable order: completed, not a test or staff order,
not cancelled before dispatch. Rebuilt daily at 5am from the shop
database. Owner of the definitions: Priya. Maintained by Callum.
config:
meta:
owner: "Priya"
maintainer: "Callum"
contains_personal_data: false
rule_set_version: 4
columns:
- name: order_id
description: "Solidus order id (spree_orders.id). Primary key."
data_tests: [unique, not_null]
- name: customer_key
description: >
Surrogate key of the deduplicated customer (see dim_customer).
Guest checkouts and accounts of the same person share one key.
- name: completed_date_uk
description: "Date the order was completed, in UK local time (Europe/London)."
- name: order_total_gross
description: "Order total as charged, including VAT and delivery, in pounds."
- name: refunded_gross
description: "All refunds linked to this order so far, including VAT, in pounds."
- name: net_revenue_ex_vat
description: '{{ doc("net_revenue") }}'
data_tests: [not_null]
After dbt run, a person who opens fct_orders in the BigQuery console sees the same descriptions as a person reading the dbt documentation site. There is one source, and it is versioned with the code.
Lineage: where a number came from, and where it goes
Lineage is the record of how data flows: which inputs a table is built from (its upstream), and which tables, dashboards and exports are built from it (its downstream). It can be recorded at two levels of detail. Table level lineage says "fct_orders reads int_orders_flagged and int_order_refunds". Column level lineage says "fct_orders.net_revenue_ex_vat is computed from these four columns in those two tables".
There are also two ways to obtain it. Design time lineage is read from code before anything runs: dbt knows its graph because every ref() declares a dependency. Runtime lineage is observed while jobs run: the warehouse logs what each query actually read and wrote. Design time lineage covers your own project perfectly and nothing else. Runtime lineage covers everything that touches the warehouse, including the BI tool and the odd script, but only what has actually run.
Lineage pays for itself in three jobs.
- Impact analysis, before a change: "If I change this column, what breaks, and who will notice?"
- Debugging, after a surprise: "This number moved. Which input moved it?"
- Compliance, when someone asks: "Where does the customer's email address end up?"
Example: impact analysis before a change
The 3PL warehouse writes to say that from 1 March its daily file will send return dates as YYYY-MM-DD instead of DD.MM.YYYY. Callum asks the lineage graph what sits downstream of the staging model for that file. The answer comes back in seconds: two intermediate models, the returns mart, the refund timing column in fct_orders, and two dashboards, the weekly returns report and the monthly management report. He now knows which tests to extend, which two people to warn, and that the change must land before the March close, not after it.
Example: debugging a number that moved
On a Tuesday morning, October's net revenue on the dashboard has dropped by £1,240 overnight, although October is long over. Callum walks the lineage upstream from the dashboard tile: the metric reads fct_orders.net_revenue_ex_vat, which depends on refunded_gross, which comes from int_order_refunds, which reads the Solidus refunds staging model. The operational metadata for that staging model shows 214 rows loaded on Monday night instead of the usual 3 or 4. A rerun of the loader had appended a batch twice, and 9 October refunds worth £1,488 including VAT were counted twice. £1,488 divided by 1.2 is £1,240, exactly the drop. Lineage turned a vague worry into a 15 minute fix and a new uniqueness test, of the kind the chapter on testing pipelines describes.
Table level lineage from the warehouse's own logs
You do not need a tool to get a first lineage graph. BigQuery records every query job in INFORMATION_SCHEMA.JOBS, with a referenced_tables array listing every table the query read and a destination_table for the table it wrote2. Turn that into pairs, and you have runtime lineage for the whole warehouse.
Example: one query for a month of lineage
This query runs in BigQuery (GoogleSQL dialect) against Wrenfield's London region, europe-west2:
-- BigQuery: which table feeds which, observed over the last 30 days
SELECT
CONCAT(ref.dataset_id, '.', ref.table_id) AS read_table,
CONCAT(j.destination_table.dataset_id, '.', j.destination_table.table_id) AS written_table,
COUNT(*) AS jobs,
MAX(j.creation_time) AS last_seen
FROM `region-europe-west2`.INFORMATION_SCHEMA.JOBS AS j,
UNNEST(j.referenced_tables) AS ref
WHERE j.creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
AND j.job_type = 'QUERY'
AND j.state = 'DONE'
AND j.error_result IS NULL
AND j.destination_table.table_id IS NOT NULL
-- results of ad hoc queries land in hidden datasets whose names start with _
AND NOT STARTS_WITH(j.destination_table.dataset_id, '_')
GROUP BY read_table, written_table
ORDER BY read_table, written_table;
A few rows of the result:
| read_table | written_table | jobs | last_seen |
|---|---|---|---|
| analytics_intermediate.int_order_refunds | analytics_marts.fct_orders | 30 | today 5.41am |
| analytics_intermediate.int_orders_flagged | analytics_marts.fct_orders | 30 | today 5.41am |
| analytics_staging.stg_solidus__orders | analytics_intermediate.int_orders_flagged | 30 | today 5.38am |
| raw_threepl.movements | analytics_staging.stg_threepl__movements | 30 | today 5.12am |
Three details matter. The view keeps 180 days of history, so a question about last spring needs your own copy of it2. referenced_tables is empty for queries answered from the cache, so a dashboard served from cache leaves no trace that day2. And reads by the BI tool usually write to those hidden result datasets, so to see which tables a dashboard reads, run the same query without the last filter and group by the user or service account instead.
Column level lineage, and the trap of filters
Table level lineage tells you that fct_orders depends on int_orders_flagged. It does not tell you whether changing one column of int_orders_flagged changes net revenue. For that you need column level lineage, and it hides a trap that catches experienced engineers.
Most column lineage tools trace where a value is derived from. But a column can change a number without being part of its formula at all. The test order flag never appears in the net revenue formula. It decides which rows exist. OpenLineage, the open standard covered in the next section, names the two cases precisely: a direct relation means the output value is derived from the input, and an indirect relation means the input affects the output without being part of it, as a filter, a join condition, a grouping, a sort, a window or a condition in a CASE does6.
Example: what a lineage tool sees, and what it misses
The open source Python library sqlglot can parse SQL and compute column lineage with its lineage() function7. Here it is applied to a simplified version of the final step of fct_orders, in BigQuery dialect. The second half of the script finds the indirect inputs that the first half cannot see.
import sqlglot
from sqlglot import exp
from sqlglot.lineage import lineage
sql = """
select
o.order_id,
o.completed_date_uk,
o.order_total_gross
- coalesce(r.refunded_gross, 0)
- o.gift_cards_sold_gross as net_revenue_gross,
o.vat_rate
from int_orders_reportable as o
left join int_order_refunds as r
on r.order_id = o.order_id
where not o.is_test_order
and o.state = 'complete'
"""
schema = {
"int_orders_reportable": {
"order_id": "INT64", "completed_date_uk": "DATE",
"order_total_gross": "NUMERIC", "gift_cards_sold_gross": "NUMERIC",
"vat_rate": "NUMERIC", "is_test_order": "BOOL", "state": "STRING",
},
"int_order_refunds": {"order_id": "INT64", "refunded_gross": "NUMERIC"},
}
# Direct lineage: which source columns is the value derived from?
node = lineage("net_revenue_gross", sql, schema=schema, dialect="bigquery")
direct = sorted(n.name for n in node.walk() if isinstance(n.expression, exp.Table))
for name in direct:
print("direct: ", name)
# Indirect lineage: columns in WHERE and JOIN ON decide which rows exist
tree = sqlglot.parse_one(sql, dialect="bigquery")
clauses = [tree.args.get("where")] + [j.args.get("on") for j in tree.args.get("joins", [])]
indirect = sorted({f"{c.table}.{c.name}" for cl in clauses if cl for c in cl.find_all(exp.Column)})
for name in indirect:
print("indirect:", name)
The output:
direct: o.gift_cards_sold_gross
direct: o.order_total_gross
direct: r.refunded_gross
indirect: o.is_test_order
indirect: o.order_id
indirect: o.state
indirect: r.order_id
A lineage graph built only from the first three lines would say that is_test_order has nothing to do with net revenue. Yet when Callum tightened the test order rule, October lost £215 of test orders from gross sales, as the business rule chapter showed. Any impact analysis for a change to a flag, a status or a join key must follow indirect lineage as well, or it will tell you, with complete confidence, that nothing downstream is affected.
OpenLineage: one format for lineage events
Every tool can compute lineage its own way. The problem starts when you have several tools: the orchestrator knows which tasks ran, dbt knows the models, the warehouse knows the queries, and none of them speaks to the others. OpenLineage is an open standard for exactly this: a common format in which any job can report what it read and what it wrote8. It is a graduate project of the LF AI & Data Foundation, and its reference implementation, the server that stores and shows the events, is called Marquez8.
The model has three entities9:
- A job is a defined piece of work, such as a dbt model or a task in a scheduler.
- A run is one execution of a job at a point in time, with its own id.
- A dataset is a table, a file or a folder that a run reads or writes.
A run sends events as it goes, usually a START and then a COMPLETE or FAIL. Everything else is a facet, a named piece of extra metadata attached to a job, a run or a dataset: the schema, the SQL, data quality results, or column lineage9. Integrations exist for Apache Airflow, Apache Spark, Apache Flink, dbt and others8.
Example: an OpenLineage event for Wrenfield's order mart
For dbt, the openlineage-dbt package provides a wrapper command, dbt-ol, which runs dbt and then reads manifest.json, run_results.json and catalog.json to emit one pair of events per model10. Callum sets two environment variables and swaps one command in his daily job:
pip install openlineage-dbt
export OPENLINEAGE_URL=http://lineage.internal.wrenfieldhome.example:5000
export OPENLINEAGE_NAMESPACE=wrenfield_prod
dbt-ol run # instead of: dbt run
The event for fct_orders then looks like this, trimmed to the parts that matter. BigQuery datasets are named bigquery plus project.dataset.table, following the OpenLineage naming rules11. Here is the event:
{
"eventType": "COMPLETE",
"eventTime": "2026-11-03T05:41:12.000Z",
"run": { "runId": "0192f0c4-7b1e-7d3a-9c55-1f2e3d4c5b6a" },
"job": { "namespace": "wrenfield_prod", "name": "wrenfield.fct_orders" },
"inputs": [
{ "namespace": "bigquery", "name": "wrenfield-data.analytics_intermediate.int_orders_flagged" },
{ "namespace": "bigquery", "name": "wrenfield-data.analytics_intermediate.int_order_refunds" }
],
"outputs": [{
"namespace": "bigquery",
"name": "wrenfield-data.analytics_marts.fct_orders",
"facets": {
"columnLineage": {
"fields": {
"net_revenue_ex_vat": {
"inputFields": [
{ "namespace": "bigquery", "name": "wrenfield-data.analytics_intermediate.int_orders_flagged",
"field": "order_total_gross",
"transformations": [{ "type": "DIRECT", "subtype": "TRANSFORMATION", "masking": false }] },
{ "namespace": "bigquery", "name": "wrenfield-data.analytics_intermediate.int_order_refunds",
"field": "refunded_gross",
"transformations": [{ "type": "DIRECT", "subtype": "TRANSFORMATION", "masking": false }] },
{ "namespace": "bigquery", "name": "wrenfield-data.analytics_intermediate.int_orders_flagged",
"field": "is_test_order",
"transformations": [{ "type": "INDIRECT", "subtype": "FILTER", "masking": false }] }
]
}
}
}
}
}]
}
The INDIRECT entry with subtype FILTER is the test order flag from the previous section, recorded in a form any catalogue that reads OpenLineage can show. The masking field says whether the input was obscured on the way, for example hashed, which matters for personal data6.
Lineage the cloud collects for you, and its limits
Google's catalogue for BigQuery, called Knowledge Catalog since 10 April 2026 (before that Dataplex Universal Catalog), can record lineage automatically: once the Data Lineage API is enabled, BigQuery reports lineage events whenever a job moves or transforms data12. That is the least effort route for a shop already on BigQuery. Read the limits before relying on it. Lineage information is kept for only 30 days. Column level lineage is not collected for a job that creates more than 1,500 column links, and it is lost when a table is swapped in with ALTER TABLE RENAME, a common pattern in rebuild jobs. Processing and storage are billed separately12.
Example: why 30 days is not enough for Wrenfield
In February, the accountant asks why the November figure in the year end pack differs from the one Priya saw in December. The lineage of the November run is three months old. The automatic lineage has forgotten it, but the dbt manifest for that run, kept with the release (Callum stores every production manifest.json next to the release tag), still has the complete graph and the SQL as it was. Design time lineage stored with each release is the long memory, and runtime lineage is the short, wide one. Keep both.
Catalogues: one place to search for data
A data catalogue is a search engine and reference book for data. It gathers the technical metadata automatically from the warehouse, dbt, the BI tool and the orchestrator, lets people add the business metadata, shows lineage, and answers the question every new analyst asks in week one: "Where is the table for this, and can I trust it?"
The common features are search, descriptions, owners, tags and classifications (such as "contains personal data"), lineage graphs, a business glossary, usage statistics (which tables people actually query) and, increasingly, data quality results shown next to each table.
The options, described fairly
| Catalogue | What it is | Notes from its own documentation |
|---|---|---|
| dbt Docs and dbt Catalog | Documentation generated from the dbt project | dbt Docs is generated locally with dbt docs generate. dbt Catalog is the hosted version in the dbt platform3. Column level lineage there needs an Enterprise or Enterprise+ plan13 |
| DataHub | Open source metadata platform, built by the company DataHub and LinkedIn | Apache 2.0 licence, self hosted or as DataHub Cloud, discovery, ownership, personal data tracking, lineage and data contracts14 |
| OpenMetadata | Open source metadata platform | Apache 2.0 licence, more than 130 connectors, column level lineage, glossaries, classifications and data contracts15 |
| Amundsen | Open source discovery tool, started at Lyft | Hosted by the LF AI & Data Foundation, archived for inactivity in September 2026, so not a choice for a new project16 |
| Knowledge Catalog (Google Cloud) | The catalogue built into Google Cloud | Ingests BigQuery metadata automatically, offers lineage and a business glossary112 |
| Snowflake Horizon Catalog | The catalogue built into Snowflake | Discovery, governance, sensitive data protection, data quality and lineage17 |
| Unity Catalog | Open source catalogue started by Databricks | Apache 2.0 licence, an LF AI & Data project, for tables, files, functions and models across Delta Lake and Apache Iceberg18 |
The vendor catalogues cost the least effort if all your data lives with that vendor. The open source platforms cover many systems but are real software to run, with their own servers, upgrades and storage. A catalogue nobody maintains is worse than none, because it looks authoritative while it goes stale.
Example: what Wrenfield actually needs
Wrenfield has one data engineer, 46 models, one warehouse, one BI tool and six people who read reports. Callum compares the options against that reality.
- Everything lives in BigQuery and dbt, so the descriptions written in YAML and copied in with
persist_docsalready show up in BigQuery and in Knowledge Catalog's automatic metadata. - The dbt documentation site, generated in the daily job and published on an internal address, gives the six readers search, descriptions and table level lineage at no extra cost.
- A self hosted DataHub or OpenMetadata would cover systems Wrenfield does not have, and would need care Callum would rather spend on tests.
His decision: dbt documentation plus the warehouse's own catalogue now, and a review when the business adds a second warehouse, a second team writing models, or more than a dozen regular data users. That threshold is a rule of thumb, not a law. The signal to watch is the number of questions in the week that start with "where is" or "which table".
A business glossary: agree on words before numbers
A business glossary is a list of the business's key terms, each with one agreed definition and an owner. It sits one level above metrics. "Customer" is a glossary term. "Active customers" is a metric built on it. If the word is fuzzy, every number built on it is fuzzy too.
The glossary is not a data dictionary. A data dictionary describes columns. The glossary describes the business, and then each column or metric links to the term it represents. Catalogues keep both, and the link between them is what lets someone search for "customer" and find the right table instead of the seven tables with a column called customer_id. For the general vocabulary of eCommerce, the eCommerce metrics glossary and the guide to marketing and business jargon are good starting points. Your own glossary adds the definitions that are specific to your business.
Example: Wrenfield's glossary, first five terms
| Term | Definition at Wrenfield | Owner | Where it lives in data |
|---|---|---|---|
| Customer | A person who has completed at least one reportable order. Accounts and guest checkouts with the same normalised email are one customer (rule customer_identity v2, which merges the 3.1% duplicates). | Priya | dim_customer, one row per customer_key |
| Order | A completed order in Solidus that is not a test, staff or checkout monitor order and was not cancelled before dispatch | Priya | fct_orders, one row per order_id |
| Return | Goods sent back and received by the 3PL, recorded in the 3PL file, matched to an order line | Priya | fct_returns |
| Net revenue | Order value after refunds and gift cards sold, without VAT, including delivery, order view, UK dates | Priya, agreed with the accountant | metric net_revenue |
| Active customer | A customer with at least one order in the 365 days up to and including the reporting date | Priya | metric active_customers |
Writing the first line took an hour of discussion, because the marketing spreadsheet counted accounts, the shop counted email addresses and GA4 counted browsers. That hour is the real work of a glossary. The table is just where the answer is kept.
Ownership: every table and every metric has a name next to it
Metadata without an owner decays. Someone has to decide what "active customer" means, approve a change to it, and answer when it looks wrong. In a small business, two roles are enough. The owner of a definition is the person accountable for its meaning, usually someone in the business. The maintainer is the person who keeps the code and data correct, usually the data engineer. At Wrenfield, Priya owns the definitions and Callum maintains them.
dbt can record this in the project. A group is a named collection of models with an owner, and each model belongs to at most one group19. A model's access setting then says who may build on it: private models can only be referenced from the same group, protected ones from anywhere in the project (the default), and public ones from any group, package or project20. One detail to remember: access in dbt controls which models may reference which. It does not grant or refuse anyone permission to read tables in the warehouse20. That is still the warehouse's job.
Example: groups and access for Wrenfield's sales models
# models/_groups.yml
groups:
- name: sales
owner:
name: Priya
email: priya@wrenfieldhome.example
description: "Orders, refunds, revenue. Definitions owned by Priya, maintained by Callum."
# models/marts/sales/_sales.yml (extract)
models:
- name: fct_orders
config:
group: sales
access: public # the stable interface for reports and other models
- name: int_orders_flagged
config:
group: sales
access: private # business rules inside sales; nobody else may build on it
Now if someone in a later marketing model writes ref('int_orders_flagged') to grab the test order flag directly, dbt refuses to parse the project and says the model is private to the sales group. The only way to orders is through fct_orders, which carries the agreed definitions.
The semantic layer: one definition, served to every tool
Even with perfect documentation, a definition written in prose is still recomputed by hand in every tool. The BI tool has its own calculated field for net revenue, the marketing spreadsheet has a formula, and the analyst's notebook has a third version in Python. They start identical and drift apart within months. This is the "three versions of revenue" problem, and documentation alone cannot end it.
A semantic layer, or metrics layer, ends it by moving the definition out of the tools and into one shared place in code. You describe your tables once: what the keys are, which columns are dimensions to group by, which are values to aggregate. You define each metric once on top. Then every tool asks the semantic layer for "net revenue by month" instead of writing SQL, and the layer generates the SQL from the one definition.
The idea is not new. Looker's modelling language, LookML, has described dimensions, measures and joins in version controlled files for years, so that SQL expressions are written "once, in one place"21. In April 2021, Benn Stancil described a standalone metrics layer as "the missing piece of the modern data stack", independent of any single BI tool22. Today the main open options are the dbt Semantic Layer, powered by MetricFlow, and Cube.
How MetricFlow thinks about your tables
MetricFlow, the engine behind the dbt Semantic Layer, is open source under the Apache 2.0 licence and is maintained by dbt Labs23. It works with a semantic graph: each dbt model can declare a semantic model, with three kinds of metadata2324.
- Entities are the join keys: the order, the customer, the product. MetricFlow uses them to find a path between tables, so you can ask for net revenue by customer region without writing the join.
- Dimensions are the ways to group and filter: a categorical one such as the delivery country, or a time dimension such as the completion date with its native granularity.
- Metrics are the numbers. A simple metric aggregates one column (sum, count, count distinct, average and others). A ratio divides one metric by another, a derived metric combines metrics in an expression, a cumulative metric aggregates over a window such as the last 365 days, and a conversion metric tracks whether one event follows another within a period25.
One practical point: from dbt version 1.12, the semantic model is written inside the model's own YAML entry, and simple metrics replace the separate "measures" of earlier versions24. Examples written for older versions look different, so check which version a tutorial targets. MetricFlow also needs a time spine, a model with one row per day, to compute cumulative metrics and fill gaps in time series26.
The definition behind the code
Before the YAML, here is net revenue as a formula, exactly as the business rule chapter set it out:
where is net revenue without VAT for the period, is the total of all orders completed in the period by UK date (including VAT and delivery), is the total of test and cancelled orders among them, is the refunds linked to those orders, is the value of gift cards sold in those orders, and is the VAT rate as a decimal, 0.20 for standard rated goods in the UK. Dividing by takes VAT out of an amount that includes it, which Foundations: percentages explains step by step.
For October 2026 at Wrenfield, is £144,245, is £1,685 (£215 of test orders and £1,470 of cancelled ones), is £10,630 (£10,320 for returns and £310 of goodwill refunds), is £1,600 and is 0.20:
In the mart, fct_orders already holds only reportable orders, so is applied there, and net_revenue_ex_vat holds each order's share of the numerator divided by . The semantic layer then only has to add it up. That split is deliberate: row level business rules stay in tested dbt models, and the semantic layer only aggregates.
Example: net revenue, orders and active customers, defined once
This is the semantic model and the metrics for fct_orders, in the dbt 1.12 format, added to the same YAML file that holds the descriptions:
# models/marts/sales/_sales.yml (continued)
models:
- name: fct_orders
semantic_model:
enabled: true
agg_time_dimension: completed_date_uk
columns:
- name: order_id
entity:
type: primary
name: order
- name: customer_key
entity:
type: foreign
name: customer
- name: completed_date_uk
granularity: day
dimension:
type: time
- name: delivery_country
dimension:
type: categorical
metrics:
- name: orders
label: Orders
description: "Reportable orders. See the glossary term Order."
type: simple
agg: count
expr: order_id
- name: gross_sales
label: Gross sales (incl. VAT)
description: "Order totals as charged, including VAT and delivery."
type: simple
agg: sum
expr: order_total_gross
- name: net_revenue
label: Net revenue
description: '{{ doc("net_revenue") }}'
type: simple
agg: sum
expr: net_revenue_ex_vat
config:
meta:
owner: "Priya"
definition_version: 4
- name: average_order_value
label: Average order value (incl. VAT)
type: ratio
numerator: gross_sales
denominator: orders
- name: customers_ordering
label: Customers who ordered
type: simple
agg: count_distinct
expr: customer_key
- name: active_customers
label: Active customers (365 days)
description: "Customers with at least one order in the 365 days up to the date."
type: cumulative
input_metric: customers_ordering
window: 365 days
The pattern for active_customers, a count of distinct customers rolled over a window, is the same one dbt's documentation uses for weekly active users25. Because customer_key is the deduplicated customer, the metric inherits the duplicate merge automatically. A person who signs in once and checks out as a guest the next time is still one active customer.
Example: asking the layer for October
With MetricFlow installed next to dbt Core (the dbt-metricflow package with the BigQuery adapter), Callum can validate the definitions and query them from the command line27:
python -m pip install "dbt-metricflow[dbt-bigquery]"
mf validate-configs
mf query --metrics net_revenue,orders,average_order_value \
--group-by metric_time__month \
--start-time '2026-10-01' --end-time '2026-10-31'
The result for October:
| metric_time__month | net_revenue | orders | average_order_value |
|---|---|---|---|
2026-10-01 | 108,608.33 | 1,980 | 72.00 |
The average order value checks out by hand: £142,560 of gross sales divided by 1,980 orders is £72.00. Adding --explain to the same command prints the SQL MetricFlow generated, which Callum reads once for every new metric, so the layer never becomes a black box27.
The important change is not the command. It is that the marketing spreadsheet, the BI tool and the management report can now all ask for net_revenue by name, through the layer's interfaces, and get £108,608.33. The GA4 figure still exists, and it should. It is just called "GA4 purchase revenue" now, with its own definition explaining that it counts what browsers reported, and nobody mistakes it for net revenue. Why GA4 and the shop disagree in the first place is the subject of the article on when analytics, ads and orders disagree.
The same idea in Cube and in LookML
Cube is an open source semantic layer, Apache 2.0 licensed for its backend, with a paid managed service called Cube Cloud28. Its data model describes cubes (usually one per table) with measures and dimensions, and a measure can carry its own filter29. Net revenue and orders for Wrenfield would look like this:
# Cube data model: model/cubes/orders.yml
cubes:
- name: orders
sql_table: analytics_marts.fct_orders
measures:
- name: count
sql: order_id
type: count
- name: net_revenue
sql: net_revenue_ex_vat
type: sum
dimensions:
- name: order_id
sql: order_id
type: number
primary_key: true
- name: completed_date_uk
sql: completed_date_uk
type: time
In LookML, the same measure is a few lines inside a view file, measure: net_revenue { type: sum sql: ${TABLE}.net_revenue_ex_vat ;; }, and lives in Git like any other code21. The difference between the three is less about syntax than about reach. LookML serves Looker. MetricFlow and Cube are designed to serve many tools through their own interfaces. Pick the one that fits the tools your people already use.
What a semantic layer costs
A semantic layer is not free, and pretending otherwise is how it ends up half built.
- Money. MetricFlow on the command line is free with dbt Core. The hosted dbt Semantic Layer, with the interfaces BI tools and spreadsheets connect to, needs a paid dbt platform account, Starter, Enterprise or Enterprise+30. On 23 November 2026 the Starter plan was listed at $100 per user per month, including 5,000 queried metrics a month31. Cube Core is open source to run yourself, and Cube Cloud is a paid service28.
- Engine support. The documentation lists Snowflake, BigQuery, Databricks, Redshift and PostgreSQL, with PostgreSQL supported on dbt v1 only23. A shop running PostgreSQL alone should check this before committing.
- A new layer to test and learn. Every metric needs a test that checks it against the reconciliation numbers, as the reporting chapter described. Generated SQL must be read at least once. And every person who used to write their own SQL must learn to ask the layer instead.
- Integration gaps. Not every BI tool can query every semantic layer. Check that the tools you use today are on the layer's list of integrations, not on its roadmap.
Example: is it worth it for Wrenfield?
Callum is the only developer, so a Starter plan would cost 1,200 a year. Against that, Callum estimates (an invented figure for the example) that the monthly "which revenue is right" discussions cost about six hours: two hours each for Priya, Callum and the accountant. At even a modest internal cost per hour, the layer pays for itself if it removes most of those hours, and that is before counting the decisions made on the wrong number.
But Wrenfield's BI tool reads tables, not semantic layer interfaces. So Callum takes a less expensive first step: he defines the metrics in MetricFlow anyway, validates them in continuous integration (CI) on every pull request, and leaves the paid interfaces for later. In the meantime, a scheduled mf query with the --csv option writes the morning's figures to a file that is loaded into a small reporting table, and the dashboard reads that table27. The definitions are written once. The paid interface can come when a second tool needs them.
One table of metric definitions
The glossary defines words. The metric table defines numbers, with every detail that decides the value. This is the table Callum publishes on the documentation site and links from every dashboard tile. Each row points to its code, so the table and the YAML cannot quietly disagree. If they ever do, the YAML wins and the table is regenerated from it.
| Metric | Definition | Time and zone | VAT | Excludes | Owner | Version |
|---|---|---|---|---|---|---|
orders | Count of reportable orders | Completion date, Europe/London | n/a | Test, staff, monitor orders, cancelled before dispatch | Priya | 4 |
gross_sales | Sum of order totals as charged | Completion date, Europe/London | Included | As for orders | Priya | 4 |
net_revenue | Gross sales minus refunds and gift cards sold, without VAT, order view | Completion date of the original order | Excluded | As for orders | Priya, agreed with the accountant | 4 |
average_order_value | gross_sales divided by orders | Completion date, Europe/London | Included | As for orders | Priya | 4 |
active_customers | Distinct deduplicated customers with an order in the last 365 days | Rolling 365 days to the reporting date | n/a | As for orders, duplicates merged (customer_identity v2) | Priya | 2 |
ga4_purchase_revenue | Purchase revenue reported by browsers in GA4 | Event date, property time zone | Included | Visitors who refused consent or block analytics | Callum | 1 |
Changing a definition without breaking trust
Definitions change. VAT rules change, a new kind of order appears, the business decides that marketplace orders count after all. The semantic layer makes a change easy to deploy, which is exactly why the process around it matters. A one line edit to a YAML file can change every report in the business by morning.
The rule is simple: separate a change of code from a change of meaning. A code change, such as a faster query, must produce the same numbers, and the tests prove it. A meaning change needs the owner's agreement, a new version number, an impact analysis through lineage (direct and indirect), and a decision about the past, which the chapter on reporting cleaned data covers in detail: restate it, or show both, never mix.
Example: marketplace orders join net revenue
In spring, Wrenfield starts selling through a marketplace, and those orders reach Solidus through an integration with the channel set to marketplace. Priya decides they count as net revenue, after the marketplace's commission is treated as a cost, not a reduction of revenue. That is a change of meaning. Callum writes version 5 of the definition, Priya signs it off, and the lineage graph lists four affected metrics and three dashboards. Because no marketplace orders existed before April, no published month changes, so no restatement is needed. The data note on the revenue tile says "from April, includes marketplace orders (definition version 5)". The YAML change, the glossary entry and the note go out in the same pull request.
Measuring whether the metadata keeps up
Documentation decays unless something checks it. The simplest useful measure is coverage: the share of columns in a layer that have a description.
where is the documentation coverage of a layer, is the number of columns in that layer with a non empty description, and is the number of columns that actually exist in the warehouse for that layer. Counting from the warehouse rather than from the YAML matters: a column added to the SQL but never mentioned in the YAML would otherwise not count at all. This is an ordinary ratio, explained in Foundations: ratios and rates.
Example: the coverage check in CI
At Wrenfield's stock take, the marts had 318 columns, 212 of them described:
where is the coverage of the mart layer. So two thirds of the mart columns were documented. Callum sets a rule: every column of a public model must have a description, and the build fails otherwise. This Python script reads catalog.json for the columns that really exist and manifest.json for the descriptions, and runs in CI after dbt docs generate:
import json
import sys
manifest = json.load(open("target/manifest.json"))
catalog = json.load(open("target/catalog.json"))
missing = []
for unique_id, node in manifest["nodes"].items():
if node["resource_type"] != "model":
continue
access = node.get("access") or node.get("config", {}).get("access")
if access != "public":
continue
documented = {
name.lower()
for name, col in node.get("columns", {}).items()
if col.get("description", "").strip()
}
actual = catalog["nodes"].get(unique_id, {}).get("columns", {})
for column in actual:
if column.lower() not in documented:
missing.append(f"{node['name']}.{column}")
if missing:
print(f"{len(missing)} public columns have no description:")
print("\n".join(sorted(missing)))
sys.exit(1)
print("Every public column is documented.")
The first run failed with 106 missing descriptions. Callum wrote them over two weeks, mart by mart, and from then on a new column without a description cannot reach the main branch. He tracks the other layers without blocking on them.
Personal data in the catalogue
Metadata has one more job that is not optional: knowing where personal data lives. Under Article 30 of the UK GDPR, an organisation must keep a record of its processing activities, including the categories of personal data, the recipients, and where possible the time limits for erasure32. There is an exemption for organisations with fewer than 250 employees, but it does not apply when the processing is not occasional32. A shop that processes customer orders every day is not processing occasionally. The Information Commission (formerly the Information Commissioner's Office, ICO) explains what the record should contain33. This is general information, not legal advice. For your own situation, ask a data protection specialist.
A record kept by hand in a spreadsheet goes stale. A record backed by metadata can be checked. If every column that holds personal data carries a tag, and lineage shows where those columns flow, the question "where does the customer's email end up?" becomes a query rather than an investigation. The next chapter in this series, on privacy engineering in pipelines, builds on exactly this.
Example: following the email address
Callum tags email in the Solidus staging model with contains_personal_data: true and category: contact. The lineage graph shows where the column goes downstream:
| Where | Form | Why it is there |
|---|---|---|
stg_solidus__orders.email | Plain text | Staging copy of the shop's orders |
int_customer_identity.email_normalised | Lower case, trimmed | Duplicate merge (customer_identity v2) |
dim_customer.email_hash | SHA 256 hash | Joining to the newsletter tool's export |
rpt_newsletter_audience | Plain text | Weekly export to the newsletter tool |
Two findings come out of this. First, dim_customer keeps only a hash, but a hash of an email is still personal data, because anyone with the email can compute the same hash. It is a pseudonym, not anonymous data, and the privacy chapter explains the difference. Second, rpt_newsletter_audience sends plain addresses to a processor, which belongs in the record of processing and in the processor checks described in the article on vetting vendors under UK GDPR. Neither finding needed a lawyer to discover. Both needed metadata.
Putting it together: the order of work for a small team
If you take one thing from this chapter, take the order. Each step is useful on its own, and each lowers the cost of the next.
- Write the glossary for your five most argued about words. Agree definitions with their owners. This is people work, and nothing else in this list works without it.
- Put descriptions next to the code. Describe every public model and column in YAML, use docs blocks for long definitions, and switch on
persist_docs. - Publish the dbt documentation site from the daily job, so everyone can search it.
- Record owners and access with dbt groups, and make every public model the one door into its subject.
- Use the lineage you already have: dbt's graph for design time, the warehouse's job log for runtime, and remember indirect lineage for flags and filters.
- Define your key metrics once in a semantic layer, starting with net revenue, orders and active customers, and validate them in CI.
- Tag personal data and let lineage answer where it flows.
- Measure coverage and fail the build when public columns lack descriptions.
- Consider a separate catalogue only when several teams, several warehouses or many readers make the built in ones too small.
Conclusion
Three numbers called revenue are not a data problem. They are a metadata problem. Each number was right, and nobody could see which question it answered. The cure has four parts. Metadata, especially the business kind that only people can write, says what every table and column means, and it belongs in the same files as the code so it changes with the code. Lineage says where every number came from and where it goes, at table level from the warehouse's own logs and at column level from the SQL, and it must include indirect lineage, because a filter changes a number without appearing in its formula. A glossary and clear ownership make sure every important word has one meaning and one person who answers for it. And a semantic layer turns the agreed definitions into code that every tool asks, so that net revenue is £108,608.33 everywhere, and the GA4 figure is honestly named as something else.
None of this needs a large team. At Wrenfield, it is a few YAML files, a script in CI, a daily documentation build and a short table of definitions. What it needs is the decision that meaning is part of the data platform, not something people carry around in their heads.
