Skip to content

Semantic layer

A semantic layer defines each business metric, what it counts and how to calculate it, in one place that dashboards, reports and AI agents all read from.

Select any words here to ask your Maestro about them.

Your store has one data warehouse. Finance has a dashboard, marketing has a report, and an AI agent writes its own SQL. All three answer "What was October revenue?" How many different numbers come back?

An online store with one data warehouse and three tools that read it. Example data.

What it is: a layer between the data warehouse and the tools that read it. It's where you write down, once, what each metric means (revenue, active customers, margin) and how it can be sliced (by month, by region). Dashboards, spreadsheets and agents ask for a metric by name, and the layer writes the SQL.

Examples: the dbt Semantic Layer (MetricFlow), Cube, Looker's LookML and Power BI semantic models.

For AI: an AI agent that writes its own SQL guesses what each column means. With a semantic layer it asks for the metric instead: the same KPI you see on the dashboard.

Build one in the course Data Modeling for AI Agents.

How it's used

A metric defined once

models/marts/fct_orders.yml

  1. models:
  2. - name: fct_ordersThe dbt model the metrics live on.
  3. semantic_model:
  4. enabled: true
  5. agg_time_dimension: ordered_at
  6. columns:
  7. - name: order_id
  8. entity:
  9. type: primary
  10. name: order
  11. - name: ordered_at
  12. granularity: day
  13. dimension:
  14. type: time
  15. metrics:
  16. - name: revenueThe name every tool asks for.
  17. type: simple
  18. agg: sum
  19. marked: expr: amount - refund_amount - tax - shippingThe business rule, written once: the amount minus refunds, tax and shipping.
The dashboard, the report and the agent ask for "revenue by month" and the layer writes the SQL. If the rule changes tomorrow, it changes in one file.

When to look closer

An agent with direct access to the tables

An agent and the semantic layer

  1. marked: The warehouse has a semantic layer that defines revenue

Your semantic layer defines revenue. An agent with SQL access answers "What was October revenue?" Which number does it use?

Ask your Maestro about Semantic layer

It answers from the free course page closest to this word, the way it answers while you study.

Example

You: What does "Semantic layer" mean, in plain words?

Your Maestro: I'll explain it with a case of yours: it sticks better than a definition. Which number at work comes out different depending on who calculates it?

Asking about: Answers from the page "How do I build a dashboard people actually use? Start here"

Only this browser keeps what you ask here. How it works

Learn more

  • Data warehouse

    A data warehouse is a database built for analysis: it brings data from many systems into one place, keeps its history and organizes it for queries.

  • dbt (data build tool)

    dbt (data build tool) turns SQL SELECT queries into tables or views in your data warehouse, runs them in order and tests the results: dbt run builds the models, dbt test checks them.

  • Star schema

    A star schema arranges data for analysis: a fact table of events, like sales, in the center, joined by keys to dimension tables (customer, product, date) that describe them.

  • KPI (key performance indicator)

    A KPI is a number a team tracks to know whether it's doing well at what matters most, like monthly sales or orders delivered on time. It only works if it's well defined, so two people who calculate it get the same answer.

The whole glossary