cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Community Articles
Dive into a collaborative space where members like YOU can exchange knowledge, tips, and best practices. Join the conversation today and unlock a wealth of collective wisdom to enhance your experience and drive success.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Metric Views in Databricks: A Unified Approach to Business Metrics

Abhilash_P
New Contributor II

Databricks has introduced a powerful featureโ€”Metric Viewsโ€”that transforms how organizations define, manage, and consume business metrics. Whether you're a data analyst, engineer, or business stakeholder, Metric Views offer a unified, governed, and reusable way to model KPIs across your reporting ecosystem.

What Are Metric Views?

Metric Views are centralized definitions of business metrics that abstract complex logic into reusable components. Registered in Unity Catalog, these views allow teams to define KPIs and use them consistently across dashboards, alerts, and data apps like Genie spaces.

Abhilash_P_0-1763445119104.png

 

Key Benefits:

  • Consistency: Define metrics once and reuse them across tools.
  • Governance: Centralized control via Unity Catalog.
  • Scalability: Supports complex schemas like star and snowflake.
  • Flexibility: Queryable via SQL, usable in BI tools.

 

Core Components of a Metric View

Metric Views are defined in YAML format and include:

Component

Description

Source

Table, view, or SQL query that feeds the metric view

Joins

Optional joins for star/snowflake schemas

Filter

Optional condition to restrict data (e.g., date filters)

Dimensions

Categorical attributes for grouping (e.g., region, product category)

Measures

Array of aggregated expressions representing business metrics.
(e.g., SUM, COUNT)

 

Metric Views vs. Standard Views

Feature

Metric View

Standard View

Purpose

Centralized KPI definition

Specific business question

Format

YAML

SQL

Governance

Unity Catalog

Schema-level

Reusability

High

Limited

Schema Support

Star & Snowflake

Typically flat or star

 

  1. Problem Statement

The Challenge of Metric Fragmentation

In most organizations, metrics are defined in multiple places:

  • SQL queries embedded in dashboards
  • Python scripts in notebooks
  • Excel sheets shared across departments

This leads to:

  •  Inconsistent definitions (e.g., โ€œactive usersโ€ varies by team)
  •  Redundant logic across tools
  •  Increased maintenance overhead
  •  Risk of misinterpretation in decision-making

Why It Matters

When metrics are fragmented:

  • Business decisions may be based on conflicting data.
  • Analysts spend time reconciling definitions instead of generating insights.
  • Scaling analytics across teams becomes difficult.

Databricksโ€™ Metric Views solve this by centralizing metric logic in a governed, reusable format.

  1. Implementation with Practical Examples / Use Cases

How to Create a Metric View

You can define Metric Views using either SQL or the Catalog Explorer UI. Here's a simplified workflow:

  1. Choose a Data Source: Table, view, or SQL query.
  2. Define Dimensions and Measures: Use YAML to specify logic.
  3. Register in Unity Catalog: Assign to a schema and catalog.
  4. Set Permissions: Ensure downstream users have access.

How Metric Views Work

Metric Views are defined using YAML, a human-readable format that specifies:

  • The data source (table/view)
  • Optional filters
  • Dimensions (grouping attributes)
  • Measures (aggregated KPIs)

These definitions are registered in Unity Catalog, making them accessible across SQL, dashboards, and Genie spaces.

Example YAML Snippet:

version: 0.1

source: samples.tpch.orders

filter: o_orderdate > '1990-01-01'

dimensions:

  - name: Order Month

    expr: DATE_TRUNC('MONTH', o_orderdate)

  - name: Order Status

    expr: CASE

      WHEN o_orderstatus = 'O' then 'Open'

      WHEN o_orderstatus = 'P' then 'Processing'

      WHEN o_orderstatus = 'F' then 'Fulfilled'

      END

  - name: Order Priority

    expr: SPLIT(o_orderpriority, '-')[1]

 

measures:

  - name: Order Count

    expr: COUNT(1)

  - name: Total Revenue

    expr: SUM(o_totalprice)

  - name: Total Revenue per Customer

    expr: SUM(o_totalprice) / COUNT(DISTINCT o_custkey)

  - name: Total Revenue for Open Orders

    expr: SUM(o_totalprice) FILTER (WHERE o_orderstatus='O')

Query a metric view

To query a metric view, you must be attached to a SQL warehouse or other compute resource running Databricks Runtime 16.4 or above.
The following sample query evaluates the three listed measures and aggregates over Order Month and Order Status. It returns results sorted by Order Month.

All measures must be wrapped in the MEASURE function.

SELECT  `Order Month`, `Order Status`,

 MEASURE(`Order Count`),

 MEASURE(`Total Revenue`),

 MEASURE(`Total Revenue per Customer`)

FROM  orders_metric_view

GROUP BY ALL

ORDER BY 1 ASC

Use Case 1: Sales Dashboard

Define metrics like:

  • Total Revenue
    Abhilash_P_1-1763445119109.png

     

  • Orders per Region
    Abhilash_P_2-1763445119112.png

     

  • Revenue per Customer

Abhilash_P_3-1763445119116.png

 

Use the same Metric View across:

  • Genie spaces
  • BI dashboards
  • SQL queries

Use Case 2: Operational Alerts

Set up alerts when:

  • Daily revenue drops below threshold
  • Order fulfillment rate falls below SLA
    Abhilash_P_4-1763445119137.png

     

Metric Views ensure the logic behind these alerts is consistent and governed.

Access Control & Security

Metric Views inherit Unity Catalogโ€™s robust access controls. You can manage privileges at the catalog, schema, and view level, ensuring secure and compliant data usage.

  1. Key Features / Benefits

Feature

Benefit

 Centralized Definitions

Define KPIs once, reuse everywhere

YAML Scripting

Human-readable, version-controlled metric logic

 Unity Catalog Integration

Governed access and discoverability

 Schema Support

Works with star and snowflake schemas

 SQL Compatibility

Query Metric Views directly in notebooks or dashboards

 Reusability

Use across Genie spaces, BI tools, and alerts

 Governance

Role-based access control via Unity Catalog

Metric Views reduce duplication, improve trust in data, and accelerate insight generation.

5: Pre-Requisites & Conclusion

Pre-Requisites

To create and use Metric Views, ensure:

  •  You have SELECT privileges on the source table/view
  • You have CREATE TABLE and USE SCHEMA privileges
  •  You have USE CATALOG privilege
  •  Youโ€™re using Databricks Runtime 16.4 or later
  • Youโ€™re working within a Unity Catalog-enabled workspace

Conclusion

Metric Views in Databricks offer a powerful solution to one of the most persistent problems in analytics: inconsistent metric definitions. By centralizing KPI logic in YAML and governing it through Unity Catalog, teams can ensure consistency, scalability, and trust in their data.

Whether you're building dashboards, triggering alerts, or scaling analytics across departments, Metric Views provide the foundation for unified, reliable business metrics.

Ready to get started? Explore the official Databricks documentation and YAML reference guide to build your first Metric View today.

@VasaviKS

1 REPLY 1

Raman_Unifeye
Contributor III

Thanks @Abhilash_P  for the detailed exapmle. Metric view is certainly a pwoerful feature to manage Business views and its already attracting many use-cases.