New: one score for how consistent your answers are. See more

Databricks metric views: a complete YAML example and how to query it

A full metric view for an orders schema, the MEASURE() queries to run on it, and what's GA, Beta or preview in December 2026.

December 1, 2026•11 min read•Vivek Sah
Jump to a section

A Databricks metric view defines a number like net revenue once, in YAML, inside Unity Catalog. Anyone can then group it by any field it exposes, whether they write SQL with MEASURE() or ask Genie. It is the core of Unity Catalog Business Semantics, which is what Databricks means today when it talks about its semantic layer. Below is a complete metric view for a realistic orders schema, the queries to run on it, which parts are GA or still Beta as of December 1, 2026, and how it compares with the dbt Semantic Layer, Snowflake semantic views and Cube.

Why a metric view instead of a regular view

A regular view fixes its aggregation when you create it. Build monthly_revenue_by_region and you get exactly that; someone who wants revenue by customer segment needs another view, and anyone who averages your monthly average order values gets a wrong number. A metric view separates the measure definition from the fields used to group and filter it, so users group by any available field and the query engine generates the computation. (Source: Databricks docs: Unity Catalog metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/, checked on 2026-12-01)

The practical difference shows up in ratios. Average order value is net revenue divided by distinct orders, and it has to be computed at whatever grain the question asks for. A metric view stores that formula and applies it at query time, so "AOV by region" and "AOV by product category" both come out right from one definition.

What's GA and what's still Beta (December 2026)

Databricks announced Unity Catalog Business Semantics as GA on April 2, 2026, with metric views at its center, and said it is open sourcing the core metric view implementation in Apache Spark. (Source: Databricks blog: Unity Catalog Business Semantics is GA, https://www.databricks.com/blog/redefining-semantics-data-layer-future-bi-and-ai, checked on 2026-12-01) Features have shipped on their own schedule since then, and several guides that still rank were written during the 2025 Public Preview.

PieceStatusNotes
Metric views (core)GA since April 2, 2026Create on Databricks Runtime 16.4+; 17.3+ recommended
Agent metadata (display names, synonyms, formats)AvailableYAML 1.1, Runtime 17.3+
Window measuresGA since October 6, 2026Trailing, cumulative and period-over-period
ParametersGA since November 13, 2026Querying needs Runtime 18.2+
Metric view listings in MarketplaceGA since November 5, 2026Publish governed metrics to consumers
Relationships between metric viewsBetaTells AI and BI tools which join path to use
Query-time joinsBetaRuntime 19+
Sharing through OpenSharingBeta
Publish to Power BI as a semantic modelPrivate PreviewAsk your account team

Sources for the table: the create page (Source: Databricks docs: Create a metric view, https://docs.databricks.com/aws/en/uc-semantics/metric-views/create, checked on 2026-12-01), feature availability (Source: Databricks docs: Metric view feature availability, https://docs.databricks.com/aws/en/uc-semantics/metric-views/feature-availability, checked on 2026-12-01), and the October (Source: Databricks release notes: October 2026, https://docs.databricks.com/aws/en/release-notes/product/2026/october, checked on 2026-12-01) and November (Source: Databricks release notes: November 2026, https://docs.databricks.com/aws/en/release-notes/product/2026/november, checked on 2026-12-01) release notes, plus the BI tools (Source: Databricks docs: Use metric views with external BI tools, https://docs.databricks.com/aws/en/uc-semantics/metric-views/bi-tools, checked on 2026-12-01) and manage (Source: Databricks docs: Manage metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/manage, checked on 2026-12-01) pages.

To create one you need SELECT on the source, CREATE TABLE and USE SCHEMA on the target schema, USE CATALOG on its catalog, and CAN USE on a SQL warehouse or compute running Runtime 17.3 or above. (Source: Databricks docs: Create a metric view, https://docs.databricks.com/aws/en/uc-semantics/metric-views/create, checked on 2026-12-01) Creating a basic metric view works from Runtime 16.4, but individual features need anything up to Runtime 19, so check each one you use against the feature availability page.

A complete metric view for an orders schema

Most published examples use the TPC-H sample tables. Here is the shape a typical ecommerce lakehouse has instead: one fact table at order-line grain and three dimension tables.

TableGrainColumns used below
main.sales.fct_order_itemsOne row per order lineorder_id, order_date, order_status, customer_id, product_id, quantity, unit_price, discount_amount, refunded_amount, is_test
main.sales.dim_customersOne row per customercustomer_id, segment, region_id
main.sales.dim_regionsOne row per regionregion_id, region_name
main.sales.dim_productsOne row per productproduct_id, category

The definition, using YAML 1.1 and the field and measure syntax from Databricks' YAML reference and modeling docs: (Source: Databricks docs: Metric view YAML syntax reference, https://docs.databricks.com/aws/en/uc-semantics/metric-views/yaml-reference, checked on 2026-12-01) (Source: Databricks docs: Advanced techniques for metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/advanced-techniques, checked on 2026-12-01)

CREATE OR REPLACE VIEW main.sales.order_metrics
WITH METRICS
LANGUAGE YAML
AS $$
version: 1.1
comment: "Orders and revenue. Excludes test orders and cancellations."
source: main.sales.fct_order_items
filter: NOT is_test AND order_status <> 'cancelled'

joins:
  - name: customer
    source: main.sales.dim_customers
    on: source.customer_id = customer.customer_id
    joins:
      - name: region
        source: main.sales.dim_regions
        on: customer.region_id = region.region_id
  - name: product
    source: main.sales.dim_products
    on: source.product_id = product.product_id

fields:
  - name: order_date
    expr: order_date
    display_name: Order Date
  - name: order_month
    expr: DATE_TRUNC('MONTH', order_date)
    display_name: Order Month
  - name: customer_segment
    expr: customer.segment
    display_name: Customer Segment
    synonyms: [segment, customer type]
  - name: region
    expr: customer.region.region_name
    display_name: Region
    synonyms: [market, geo]
  - name: product_category
    expr: product.category
    display_name: Product Category
    synonyms: [category]

measures:
  - name: gross_revenue
    expr: SUM(quantity * unit_price)
    display_name: Gross Revenue
  - name: net_revenue
    expr: SUM(quantity * unit_price - discount_amount - refunded_amount)
    display_name: Net Revenue
    comment: "Gross revenue minus discounts and refunds."
    synonyms: [revenue, sales]
  - name: order_count
    expr: COUNT(DISTINCT order_id)
    display_name: Orders
  - name: customer_count
    expr: COUNT(DISTINCT customer_id)
    display_name: Customers
  - name: avg_order_value
    expr: MEASURE(net_revenue) / MEASURE(order_count)
    display_name: Average Order Value
    synonyms: [AOV]
  - name: refund_rate
    expr: SUM(refunded_amount) / NULLIF(SUM(quantity * unit_price), 0)
    display_name: Refund Rate
  - name: net_revenue_7d
    expr: SUM(quantity * unit_price - discount_amount - refunded_amount)
    display_name: Net Revenue, Trailing 7 Days
    window:
      - order: order_date
        range: trailing 7 day
  - name: net_revenue_month
    expr: SUM(quantity * unit_price - discount_amount - refunded_amount)
    window:
      - order: order_month
        range: current
  - name: net_revenue_prior_year
    expr: SUM(quantity * unit_price - discount_amount - refunded_amount)
    window:
      - order: order_month
        range: current
        offset: -12 month
  - name: net_revenue_yoy
    expr: (MEASURE(net_revenue_month) - MEASURE(net_revenue_prior_year)) / NULLIF(MEASURE(net_revenue_prior_year), 0)
    display_name: Net Revenue YoY Growth
$$;

What each choice in that definition does:

  1. The filter runs on every query. Test orders and cancellations can't leak into any number built on this view, which is the most common reason two dashboards disagree.
  2. Joins default to many-to-one. Each order line has one customer and one product, so that default is right here. The region join nested under customer is a snowflake join, referenced as customer.region.region_name, and needs Runtime 17.3+. (Source: Databricks docs: Metric view feature availability, https://docs.databricks.com/aws/en/uc-semantics/metric-views/feature-availability, checked on 2026-12-01)
  3. avg_order_value is composed from two other measures with MEASURE() inside the expression, so changing the definition of net revenue changes AOV with it.
  4. Window measures order by a field the view exposes (order_date, order_month). A query that breaks results down over time has to reference that field too, or the windows come out wrong. (Source: Databricks docs: Advanced techniques for metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/advanced-techniques, checked on 2026-12-01) The prior-year offset needs YAML 1.1 and Runtime 18.1+.
  5. Synonyms and display names are for Genie and other agents. A user who asks for "sales by market" gets net_revenue by region because the view says so. Each field or measure takes up to 10 synonyms. (Source: Databricks docs: Metric view YAML syntax reference, https://docs.databricks.com/aws/en/uc-semantics/metric-views/yaml-reference, checked on 2026-12-01)

If you prefer clicking, Catalog Explorer has a Create > Metric view flow with a UI tab, a YAML editor and Genie Code to draft the definition. (Source: Databricks docs: Create a metric view, https://docs.databricks.com/aws/en/uc-semantics/metric-views/create, checked on 2026-12-01)

Querying it with MEASURE()

Monthly net revenue and AOV by region, for one category:

SELECT
  order_month,
  region,
  MEASURE(net_revenue)     AS net_revenue,
  MEASURE(avg_order_value) AS aov
FROM main.sales.order_metrics
WHERE product_category = 'Footwear'
GROUP BY ALL
ORDER BY order_month, region;

Year-over-year growth by customer segment, using the window measures:

SELECT
  order_month,
  customer_segment,
  MEASURE(net_revenue_month)      AS net_revenue,
  MEASURE(net_revenue_prior_year) AS prior_year,
  MEASURE(net_revenue_yoy)        AS yoy_growth
FROM main.sales.order_metrics
WHERE order_month >= '2026-01-01'
GROUP BY ALL
ORDER BY order_month;

The rules that trip people up, from Databricks' query docs: (Source: Databricks docs: Query metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/query, checked on 2026-12-01)

  • SELECT * fails. List fields explicitly.
  • Every measure goes inside MEASURE(). On Runtime 18.1+ you can write AGG() instead.
  • Names with spaces need backticks (MEASURE(`Total Revenue`)). Snake_case names plus a display_name, as above, avoid that in SQL while dashboards and Genie still show the friendly label.
  • Joining a metric view to another table at query time is Beta. The stable pattern is to aggregate in a CTE first and join the result.
  • DESCRIBE TABLE EXTENDED main.sales.order_metrics AS JSON returns the full YAML in its View Text field, which is the quickest way to see what a view actually defines.

Where metric views show up

The point of defining a number in Unity Catalog is that every surface reads the same definition. Here is how each one gets to it today.

WhereHow it uses the metric viewWatch for
SQL editor, notebooks, alertsMEASURE() queriesRuntime 16.4+
AI/BI dashboardsBuild a dataset on the metric view; promote dashboard logic into one
Genie AgentsAdd it as a data asset next to tables and views50 assets per agent in total
Genie OneReads Unity Catalog semantics through Genie OntologyGA since November 9, 2026
Power BINative query with MEASURE() in DirectQuery; publish as a semantic modelPublishing is Private Preview
TableauOne RAWSQLAGG_REAL("MEASURE(%1)", ...) calculated field per measure, or Custom SQLPass-through may fail on published or federated data sources
Sigma, other JDBC/ODBC toolsCustom or pass-through SQL with MEASURE()
Claude or ChatGPT over MCPThrough Genie's MCP servers, or SQL that writes MEASURE()Below

Sources: the GA announcement for dashboards and Genie (Source: Databricks blog: Unity Catalog Business Semantics is GA, https://www.databricks.com/blog/redefining-semantics-data-layer-future-bi-and-ai, checked on 2026-12-01), Genie Agent best practices (Source: Databricks docs: Genie Agent best practices, https://docs.databricks.com/aws/en/genie-agents/best-practices, checked on 2026-12-01), the Unity Catalog semantics overview (Source: Databricks docs: Unity Catalog semantics, https://docs.databricks.com/aws/en/uc-semantics/, checked on 2026-12-01), the November release notes (Source: Databricks release notes: November 2026, https://docs.databricks.com/aws/en/release-notes/product/2026/november, checked on 2026-12-01) and the BI tools page. (Source: Databricks docs: Use metric views with external BI tools, https://docs.databricks.com/aws/en/uc-semantics/metric-views/bi-tools, checked on 2026-12-01)

Databricks' own Genie guidance is direct about it: metric views are "particularly effective for Genie Agents because they pre-define metrics, dimensions, and aggregations," and when a subject area needs more than 50 assets, it recommends pre-joining tables into views or metric views. (Source: Databricks docs: Genie Agent best practices, https://docs.databricks.com/aws/en/genie-agents/best-practices, checked on 2026-12-01)

Metric views from Claude or ChatGPT

There are two routes, and they behave differently.

Through Genie, the agent never sees YAML. The Genie One MCP server (GA) and the per-agent Genie Agent endpoint (Public Preview) let Claude or ChatGPT send a question in plain English; Genie answers it from whatever metric views are in its context. (Source: Databricks docs: Genie One MCP server, https://docs.databricks.com/aws/en/agents/mcp-tools/genie-mcp, checked on 2026-12-01) (Source: Databricks docs: Genie Agent MCP server, https://docs.databricks.com/aws/en/agents/mcp-tools/genie-agent, checked on 2026-12-01) Setup for both is in How to connect Claude to Databricks.

Through SQL, the agent writes its own queries. Databricks says its SQL MCP server has no semantic context and runs the SQL it receives without resolving business terms or metric definitions. (Source: Databricks docs: Databricks SQL MCP server, https://docs.databricks.com/aws/en/agents/mcp-tools/databricks-sql, checked on 2026-12-01) A metric view still works over that connection, but only if the agent knows it exists and wraps each measure in MEASURE(). We saw the same thing with Snowflake's version: connected over SQL, Claude went straight to the raw tables and used the semantic view only when asked, or when a Claude Project instruction told it to look for one first (the full test). Expect a model that has never seen your workspace to go to fct_order_items and write its own revenue formula. Naming the metric views in the agent's standing instructions closes most of that gap.

Metric views vs the dbt Semantic Layer, Snowflake semantic views and Cube

All four store metric definitions as code next to the data. They differ in where they run and who can read them.

Databricks metric viewsdbt Semantic LayerSnowflake semantic viewsCube
Defined inYAML inside CREATE VIEW ... WITH METRICS, or the Catalog Explorer UIYAML semantic models and metrics in your dbt projectCREATE SEMANTIC VIEW SQL, or a YAML spec uploaded through AutopilotYAML or JavaScript in version control
Query withMEASURE() in Databricks SQLSemantic Layer APIs and partner integrationsSEMANTIC_VIEW() in a FROM clausePostgres-compatible SQL with MEASURE, REST, GraphQL
Runs onDatabricksSnowflake, BigQuery, Databricks, Postgres, RedshiftSnowflakeYour warehouse, through Cube
AI accessGenie, Genie One MCPdbt MCP server for Claude and ChatGPTCortex Analyst, Cortex AgentsCube's MCP server
What you payIncluded in Databricks; compute billedMetricFlow is Apache 2.0; the hosted layer needs a dbt Starter or Enterprise planIncluded in Snowflake; credits billedCube Core is open source; the hosted platform is paid
Fits whenData and BI already live in Unity CatalogMetrics should follow your dbt models across warehousesData lives in Snowflake and Cortex is the AI surfaceSeveral apps or customers query one model through an API

Sources: dbt Semantic Layer (Source: dbt docs: dbt Semantic Layer, https://docs.getdbt.com/docs/use-dbt-semantic-layer/dbt-sl, checked on 2026-12-01) and MetricFlow (Source: dbt docs: About MetricFlow, https://docs.getdbt.com/docs/build/about-metricflow, checked on 2026-12-01) docs, Snowflake's semantic view overview (Source: Snowflake docs: Overview of semantic views, https://docs.snowflake.com/en/user-guide/views-semantic/overview, checked on 2026-12-01) and SEMANTIC_VIEW reference (Source: Snowflake docs: SEMANTIC_VIEW, https://docs.snowflake.com/en/sql-reference/constructs/semantic_view, checked on 2026-12-01), and Cube's introduction. (Source: Cube docs: Introduction, https://docs.cube.dev/docs/introduction, checked on 2026-12-01)

The interesting row for a Databricks team on dbt is the first one. Run both and you define net revenue twice, once in dbt YAML and once in a metric view, and they will drift. The formats may converge: Databricks has joined Apache Ossie (incubating), an open semantics effort, (Source: Databricks blog: Unity Catalog Business Semantics is GA, https://www.databricks.com/blog/redefining-semantics-data-layer-future-bi-and-ai, checked on 2026-12-01) and dbt v1.12 can define semantic models from Apache Ossie documents. (Source: dbt docs: Apache Ossie semantic layer documents, https://docs.getdbt.com/docs/build/ossie-semantic-models, checked on 2026-12-01) Until a metric definition round-trips between the two, pick one home for each metric and treat the other as a consumer. For a broader version of this comparison, see Cube vs dbt Semantic Layer vs Contextflo and Claude with Snowflake semantic views for the Snowflake side tested end to end.

Who maintains a metric view

A metric view is code that a person owns, and Databricks' rules make that ownership concrete:

  • Only the owner can edit the definition. For shared editing, transfer ownership to a group; that group then needs SELECT on every table the view reads. (Source: Databricks docs: Manage metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/manage, checked on 2026-12-01)
  • Materialized metric views can't be group-owned, and once a materialization exists the owner can't be changed. (Source: Databricks docs: Materialization for metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/materialization, checked on 2026-12-01) If you want both speed and a team of editors, decide which views get materialized before you hand them to a group.
  • ALTER VIEW replaces the whole YAML, so every edit resends the full definition, and DROP VIEW can't be undone. (Source: Databricks docs: Manage metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/manage, checked on 2026-12-01) Upgrading an older view to YAML 1.1 with ALTER VIEW drops its Unity Catalog comments unless you copy them into comment fields first. (Source: Databricks docs: Metric view YAML syntax reference, https://docs.databricks.com/aws/en/uc-semantics/metric-views/yaml-reference, checked on 2026-12-01)
  • Materialization can't be used on a view whose sources have row filters, column masks or ABAC policies, or on a view with parameters. Refreshes run as managed Lakeflow pipelines billed as pipeline usage, and without a schedule the materialized data goes stale until someone refreshes it. (Source: Databricks docs: Materialization for metric views, https://docs.databricks.com/aws/en/uc-semantics/metric-views/materialization, checked on 2026-12-01)

Because each edit is a full replacement, the CREATE OR REPLACE VIEW statement belongs in a Git repo and goes through review like any dbt model, deployed by the same job that runs the rest of your SQL. In practice that means the analytics engineer who owns the gold layer also owns the metric views on top of it, and every new metric waits for that person.

The context a metric view doesn't hold

A metric view covers the numbers someone has already modeled. People ask about the rest of the warehouse too: what a table holds, which customer_id is the real one, which rows are test data, and how Databricks data lines up with Postgres, Snowflake or a spreadsheet the finance team uploads.

Contextflo covers that layer, and it works alongside your metric views: the modeled KPIs stay in Unity Catalog, and Claude or ChatGPT get context for everything else. Point it at the GitHub or GitLab repo that builds your gold tables and it describes each table and column from the code, the schema and your docs. Setup takes about 10 minutes, and the context sharpens as your team saves corrections and checked queries.

It reaches past Databricks to Snowflake, BigQuery, Postgres and uploaded files in the same conversation, and it works with the Claude or ChatGPT subscription your team already pays for, so one AI bill and you pick the model. It supports access control across all data sources, at the granularity each underlying data source supports, on every plan. Pricing is from $500/month for up to 10 people, unlimited queries, and it's free for one user and one data source.

Here is a more in-depth look at Contextflo and how it works.

What is Contextflo?

Contextflo is a governed context layer between your data and the AI your team already uses. Connect your warehouse once, and your team asks questions in their own Claude or ChatGPT. The model writes and runs the SQL; Contextflo supplies the definitions, the per-user access control, and the audit that make the answers trustworthy. Your data never moves, and you do not need a data team.

How it works

1
Connect your data
Point Contextflo at your warehouse or database, or upload a CSV. It reaches multiple sources at once, so a single question can span all of them.
2
Bootstrap your context layer and review
Connect your code repo, Notion docs, or a data dictionary, and Contextflo annotates each table in your data source where it can. You review and correct them. That becomes the foundational context layer: your AI agent does not just see tables, it sees the context around them.
3
Define metrics and save golden queries
Pin the verified SQL behind a metric once. Every question then resolves against the same definitions, so the number is consistent no matter who asks or how they phrase it.

Contextflo, explained by our founder.

Your team queries in their own Claude or ChatGPT over MCP, so you bring any agent rather than a locked-in bot, and every answer comes back with the SQL shown and access enforced per user.

FAQ

What is a Databricks metric view? A metric view is a Unity Catalog object that defines business measures, like net revenue or order count, once in YAML, separately from the fields you group them by. You query it with MEASURE() and can group by any field it exposes, and the engine generates the right aggregation. Metric views are the core of Unity Catalog Business Semantics, Databricks' semantic layer.

Are Databricks metric views generally available? Yes. Databricks announced Unity Catalog Business Semantics, with metric views at its center, as generally available on April 2, 2026. Window measures went GA in October 2026 and parameters in November 2026. Relationships between metric views and query-time joins are still in Beta, and publishing a metric view to Power BI as a semantic model is in Private Preview.

How do you query a Databricks metric view? List the fields you want, wrap every measure in MEASURE() (or AGG on Databricks Runtime 18.1 and above), and group by the fields, for example SELECT region, MEASURE(net_revenue) FROM main.sales.order_metrics GROUP BY ALL. SELECT * is not supported on a metric view.

Does Databricks Genie use metric views? Yes. You can add metric views to a Genie Agent alongside tables and views, up to 50 assets per agent, and Databricks calls them particularly effective for Genie because they pre-define metrics, dimensions and aggregations. Genie One reads them as part of Genie Ontology, which went GA in November 2026.

Can Claude or ChatGPT use Databricks metric views? Yes. Through the Genie One MCP server or a Genie Agent's MCP endpoint, Claude and ChatGPT ask Genie, which answers from the metric views in its context. Any SQL connection can also query a metric view directly, as long as the agent knows the view exists and writes MEASURE() for each measure.