MetricFlow YAML examples and implementation guide

Understand how MetricLayer generates MetricFlow YAML and adapt the snippets for your semantic models, measures, and metrics.

1. Define semantic models

Group tables by business entity. Set the default time dimension and declare entities to anchor joins.

2. Add measures and dimensions

Measure definitions describe aggregation and expressions. Dimensions capture grain, filters, and categoricals.

3. Publish metrics

Wrap core measures in MetricFlow metrics, declare filters, and expose them to dbt Cloud or the Semantic Layer API.

Semantic model snippet

semantic_models:
  - name: ecommerce_orders
    model: ref('stg_orders')
    defaults:
      agg_time_dimension: order_date
    entities:
      - name: order
        type: primary
      - name: customer
        type: foreign
    dimensions:
      - name: order_date
        type: time
        type_params:
          time_granularity: day
      - name: channel
        type: categorical
    measures:
      - name: total_revenue
        agg: sum
        expr: revenue

Metric definition

metrics:
  - name: revenue
    type: simple
    type_params:
      measure: total_revenue
    filter:
      - field: order_date
        operator: ">="
        value: "2023-01-01"