Monday
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.
Key Benefits:
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. |
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 |
The Challenge of Metric Fragmentation
In most organizations, metrics are defined in multiple places:
This leads to:
Why It Matters
When metrics are fragmented:
Databricksโ Metric Views solve this by centralizing metric logic in a governed, reusable format.
How to Create a Metric View
You can define Metric Views using either SQL or the Catalog Explorer UI. Here's a simplified workflow:
How Metric Views Work
Metric Views are defined using YAML, a human-readable format that specifies:
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:
Use the same Metric View across:
Use Case 2: Operational Alerts
Set up alerts when:
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.
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:
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
yesterday
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.
yesterday
Passionate about hosting events and connecting people? Help us grow a vibrant local communityโsign up today to get started!
Sign Up Now