offdataai
DatabricksSemantic LayerUnity CatalogMetrics

Semantic Layer for Databricks: Metric Views, Genie and Your Options

How to build a semantic layer on Databricks with Unity Catalog metric views, how Genie and AI/BI use them, when to use dbt or a universal semantic layer instead, and how to keep definitions portable.

ooffdataai3 min read

On Databricks, the native way to build a semantic layer is with Unity Catalog metric views: governed objects that define dimensions and measures over your tables, queried with SQL and used by Genie and AI/BI dashboards. You can also use the dbt Semantic Layer or a universal semantic layer on top of Databricks SQL. This guide shows how metric views work and when each option fits.

Unity Catalog metric views

A metric view is defined in YAML and created with SQL. It names a source table, optional joins, dimensions and measures:

sql
CREATE OR REPLACE VIEW main.sales.order_metricsWITH METRICSLANGUAGE YAMLAS $$version: 1.1source: main.sales.fct_ordersdimensions:  - name: order_month    expr: DATE_TRUNC('MONTH', order_date)  - name: region    expr: regionmeasures:  - name: net_revenue    expr: SUM(net_amount)  - name: order_count    expr: COUNT(1)  - name: average_order_value    expr: SUM(net_amount) / COUNT(1)$$;

You query it with the MEASURE() function, and Databricks computes each measure correctly at whatever grain you group by:

sql
SELECT order_month, region, MEASURE(net_revenue), MEASURE(average_order_value)FROM main.sales.order_metricsGROUP BY ALL;

Because the ratio is defined once, nobody averages pre-computed averages by mistake. Check the Databricks documentation for the current YAML specification, as it is still evolving.

Why metric views matter for Genie

Genie, Databricks' natural-language interface, answers questions by writing SQL. Given only tables, it has to infer joins and formulas. Given metric views, it can select approved measures and dimensions by name, so answers match your dashboards. Adding clear descriptions and synonyms to measures and dimensions improves it further.

Other ways to build a semantic layer on Databricks

OptionWhen it fits
Unity Catalog metric viewsMost data is on Databricks, and Genie, AI/BI and Databricks SQL are the main consumers
dbt Semantic LayerYou build models with dbt on Databricks and want metrics versioned in the same project
Universal semantic layer (AtScale, Cube)Several BI tools, Excel, or embedded analytics need one model
Power BI semantic modelReporting is mostly in Power BI on Databricks data

Many teams combine them: definitions kept in one neutral place and published to Databricks as metric views, so Genie benefits without the definitions being locked to one platform. See best semantic layer tools.

Getting the model right first

Metric views sum and count whatever the source table holds. If a fact table mixes grains or joins fan out, the metric view returns wrong numbers consistently. Before creating metric views, make sure each fact has a declared grain, dimensions are conformed, and relationships have the right cardinality.

Frequently asked questions

Does Databricks have a semantic layer?

Yes. Unity Catalog metric views provide governed dimensions and measures, used by Databricks SQL, AI/BI dashboards and Genie.

What is the difference between a metric view and a normal view?

A normal view returns fixed rows. A metric view defines measures that are computed at whatever grouping you query, with the MEASURE() function, so ratios and distinct counts stay correct.

Can I use the dbt Semantic Layer with Databricks?

Yes, the dbt Semantic Layer supports Databricks as a platform.

Publish metric views from your data model

offdataai derives metrics from a validated data model and publishes them to Databricks as Unity Catalog metric views, reading query history to suggest which joins and measures matter, so Genie answers from approved definitions. The same definitions also export to dbt, Snowflake semantic views and Apache Ossie. See the Databricks data model generator and our Unity Catalog comparison.

Try offdataai

Ship a warehouse from a single conversation.

Describe your domain. Get ERDs, DDL, dbt projects, and seed data for every major cloud warehouse.

Start building

Keep reading

All posts →