Request a demo

Glossary · Data architecture

What is semantic layer?

A semantic layer defines business metrics, dimensions and joins once, in code, and translates requests from BI tools, notebooks or AI assistants into SQL against the warehouse, so everyone gets the same answer for the same metric. LookML in Looker is a widely used example.

Also called: metrics layer, semantic model, LookML, headless BI, universal semantic layer

Why a semantic layer exists

Without one, every dashboard and analyst writes their own SQL for "revenue" or "active customer". Definitions drift: one excludes refunds, another doesn't, and two reports disagree in the same meeting. A semantic layer moves those definitions into a single, version-controlled model. Tools ask for "revenue by country last month", and the layer writes the joins, filters and aggregations.

This matters more as AI assistants query data. An assistant that can look up that total_revenue is a sum of amount excluding refunds doesn't have to guess the definition from raw column names.

LookML: Looker's semantic layer

In Looker, the semantic model is written in LookML. Views describe tables and their fields; explores declare how views join. A minimal view over a BigQuery table:

view: orders {
  sql_table_name: `my-project.sales_mart.fct_orders` ;;

  dimension: order_id {
    primary_key: yes
    type: string
    sql: ${TABLE}.order_id ;;
  }

  dimension: country {
    type: string
    sql: ${TABLE}.country ;;
  }

  dimension: status {
    type: string
    sql: ${TABLE}.status ;;
  }

  dimension_group: created {
    type: time
    timeframes: [date, week, month]
    sql: ${TABLE}.created_at ;;
  }

  measure: total_revenue {
    type: sum
    sql: ${TABLE}.amount ;;
    filters: [status: "-refunded"]
  }
}

The filters line excludes refunded orders from the measure everywhere it is used. LookML projects live in Git, so metric changes go through review like code. Other semantic layers follow the same pattern in YAML or SQL: the dbt Semantic Layer (MetricFlow), Cube and AtScale.

Effect on BigQuery cost

A semantic layer generates the SQL, so it also decides what each dashboard costs:

  • Generated queries can be wide. A poorly modeled explore joins tables a question doesn't need. Check the SQL tab of expensive dashboards.
  • Partition filters. Make date filters required on large explores, so queries prune partitions instead of scanning all history.
  • Aggregates and caching. Looker's persistent derived tables and aggregate awareness, BigQuery materialized views and BI Engine let common questions read small precomputed tables. Each also costs storage or refresh compute, so check that the aggregates get used.
  • Who pays. Queries run under the BI tool's service account, so attribute them by dashboard or explore through labels or query comments; otherwise all BI spend looks like one user.

Common pitfalls

  • Definitions in two places. A metric defined in a dbt model and again in LookML will drift; decide where each definition lives.
  • Semantic layer as a fix for bad tables. It works best on clean, modeled gold tables, not raw data.
  • No ownership. Metric definitions need owners, just like data products.

FAQ

What is the difference between a semantic layer and a data mart?

A data mart stores modeled tables. A semantic layer stores definitions: which column is revenue, how it aggregates, which tables join and how. It usually sits on top of marts and generates the SQL at query time.

Is dbt a semantic layer?

dbt models build tables. The dbt Semantic Layer, based on MetricFlow, is a separate component that defines metrics on top of those models. Looker's LookML, Cube and AtScale are other semantic layers.

Read next

Browse the full glossary

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.