Skip to main content

Create and edit metric views

This page explains how to create and edit metric views using the Catalog Explorer UI or SQL. The Catalog Explorer UI includes a low-code editor and a YAML editor. The low-code UI is a good starting point if you prefer not to write SQL.

For a more complex example, see Tutorial: Build a complete metric view with joins.

Prerequisites

Before you create or edit a metric view, verify that you have the following permissions:

  • SELECT privileges on the table-like asset or SQL query used as the source.
  • CREATE TABLE and USE SCHEMA privileges in the schema where you want to create the metric view.
  • USE CATALOG privilege on the parent catalog.
  • CAN USE permission on a SQL warehouse or other compute resource running Databricks Runtime 17.3 or above.

A metastore admin or catalog owner can grant all of these privileges. A schema owner or user with MANAGE privilege can grant USE SCHEMA and CREATE TABLE privileges on the schema.

Create a metric view

You can create a metric view using the Catalog Explorer UI, SQL, or the YAML editor.

The Catalog Explorer low-code UI enables you to define dimensions and measures interactively without writing YAML directly.

  1. Click Data icon. Catalog in the workspace sidebar.

  2. Use the search bar to find your source table. For example, search for samples.tpch.orders.

  3. Click the table name to show table details.

  4. Click Create > Metric view. In the Create metric view dialog, enter a name and select a catalog and schema destination. Then click Create.

    Create metric view dialog.

  5. Click UI to open the low-code editor, if necessary.

Define dimensions

Dimensions are categorical attributes used for grouping and filtering, such as order month or order status. All source columns are added as dimensions automatically.

  1. Click Add or plus icon Add under Dimensions.
  2. To define a dimension expression, type a SQL expression in the expression field. For example, type DATE_TRUNC('month', o_orderdate) to group orders by month.
  3. Optionally, click Pencil sparkle icon. Generate with AI to use Genie Code to suggest a dimension expression.
  4. Optionally, enter a Display name, Comment, Synonyms, Format, or Tags. Format is only available for numeric, date, and datetime columns.

Define measures

Measures are aggregate expressions that produce business metrics, such as total revenue or order count.

  1. Click Add or plus icon Add under Measures.

  2. Enter a SQL aggregate expression in the expression field. For example, type SUM(o_totalprice) to calculate total revenue.

  3. Optionally, click Pencil sparkle icon. Generate with AI to use Genie Code to suggest a measure expression.

  4. Optionally, enter a Display name, Comment, Synonyms, Format, or Tags.

    Add a measure in the metric view UI.

    To preview a measure, click Play Icon Preview next to the measure name. The preview shows the measure results for a selected time window and dimension.

    Preview a measure in the metric view UI.

  5. Click Save.

Any user with at least SELECT privileges can now query the metric view. To learn more about managing permissions, see Set permissions.

Generate a metric view with Genie Code

Genie Code can generate a metric view definition from a plain-language description:

  1. Click the Genie Code icon Avatar assistant icon. in the upper-right corner of your workspace.
  2. Describe the metric view you want to create. Genie Code returns SQL DDL.
  3. Copy the SQL and paste it into the SQL editor. Click Run.
  4. Edit the SQL or open the metric view editor to make adjustments. See Edit a metric view.

Edit a metric view

You must be the owner of a metric view to edit its definition. To enable collaborative editing, transfer ownership to a group. See Enable collaborative editing.

  1. Find the metric view in Catalog Explorer.
  2. Click Edit to open the editor.
  3. Click UI to view the low-code UI.
  4. Click the measure or dimension you want to edit. Make your changes and click Save.
  5. To add a new dimension or measure, click Add or plus icon Add in the section you want to edit. See Create a metric view for detailed instructions about defining new measures and dimensions.

Next steps

After creating a metric view, use the following resources to query, manage, and extend your work.

Query and consume

Manage and govern

Advanced features

Examples