Module 12 of 16

MetricFlow and the dbt Semantic Layer

See how dbt semantic models produce governed SQL at query time.

Updated

115 minutes1 exercisesFree

Start here

Learning objectives

  • Understand semantic model YAML at a high level
  • Know what MetricFlow does
  • Explain how governed metrics can serve BI, apps, and AI
MetricFlow and the dbt Semantic Layer Follow the arrows. Each box is one idea you will practice in this module. YAML step 1 Graph step 2 Metric step 3 SQL step 4 Result step 5 Production analytics engineering turns raw records into governed, trusted business meaning.

The Mental Model

MetricFlow powers the dbt Semantic Layer by using semantic model and metric definitions to generate SQL dynamically for requested metrics and dimensions.

You define the rules once. MetricFlow acts like a careful translator that writes the SQL for each question using those rules.

Dataset reference: ecommerce tables and grain assumptions.

Review a semantic query plan

Use this conceptual plan to review a MetricFlow query. It is a design checklist, not a version-specific YAML configuration.

DefinitionExampleReview question
Entityorder and customerWhich side is unique?
MeasureSum of net_amountIs the input already at order grain?
Time dimensionorder_dateWhich timezone and day boundary apply?
Group-by dimensioncustomer countryCurrent country or country at order time?

Compile a query for the same two-country fixture from the previous lesson and inspect the joins in the generated SQL. Compare its result with the hand-checked totals before exposing it to dashboards. Central generation makes a definition reusable; an incorrect definition can still produce consistently incorrect results.

Acceptance check: no many-to-many join is introduced, and adding a second measure does not change the first measure's total.

Interactive Check

Question: Why is generated SQL safer than each dashboard author writing their own revenue SQL?

Reveal the answer

The generated SQL comes from one governed metric definition, so all tools use the same calculation, joins, and time rules.

Practice: Read a Semantic Model YAML

Identify entities, measures, dimensions, and metrics in a simplified YAML snippet.

Use the guided lab below to record your result, assumptions, and the check that would catch an incorrect result.

Production notes

Keep these close

  • Keep semantic definitions close to the dbt models they describe. Distance creates drift.

Common mistakes

What usually breaks

  • Confusing measures and metrics
  • Creating semantic definitions on untested models
  • Exposing dimensions that create unsafe joins

Key terms

Vocabulary used in this module

MetricFlow

The query engine used by the dbt Semantic Layer to generate metric SQL.

Semantic model

A definition that describes entities, measures, and dimensions for a dbt model.

Exercises

Practice inside the lesson

30-45 minutesBeginner to Intermediate

Read a Semantic Model YAML

Identify entities, measures, dimensions, and metrics in a simplified YAML snippet.

  1. Circle the primary entity
  2. Find the revenue measure
  3. Find the order date time dimension
  4. Find the revenue metric
  5. Explain how a query could ask for revenue by month

Expected evidence

A short answer, SQL/YAML snippet, or lineage map that can live directly in the course page notes.

Recap

Key takeaways

  • MetricFlow generates SQL from semantic definitions
  • The dbt Semantic Layer connects governed metrics to many consumers
  • Semantic YAML should be reviewed like production code

Related resources

Keep learning across CodersSecret