Skip to main content

Use metric views with external BI tools

You can query Unity Catalog metric views from external BI tools through any SQL-based connection. The available patterns trade off setup effort against capability, so the sections below help you select the right approach for each tool and link to the configuration steps and limitations.

Choose an approach​

The following table describes the patterns for working with metric views when your existing workloads are in partner BI tools.

Pattern

When to use

Import data model with Genie Code

Use the /importBI skill to import your data model to Databricks.

Custom SQL with MEASURE()

The tool passes SQL queries to Databricks (for example, using a built-in query or custom SQL option). Most BI tools support this approach.

Pass-through functions in Tableau

You want Tableau to generate the query, so filters, sorts, and table calculations work as usual. You define a calculated field for each measure that wraps it in MEASURE(). See Compare pass-through functions to BI compatibility mode.

Wrapper view

You want to avoid writing SQL in the BI tool. You define a standard view that wraps the metric view with the MEASURE() logic, then point the tool at that view like any other table.

BI compatibility mode

The tool can't pass custom SQL queries to Databricks and instead generates standard aggregations (SUM, COUNT) against measure columns. Databricks rewrites the generated queries to apply the correct measure logic. See Use BI compatibility mode to query metric views for supported scenarios, best practices, and limitations. In Tableau, pass-through functions avoid the aggregation limitations of the rewrite.

Built-in partner integration

The partner has added built-in support for metric views, so measures and dimensions appear directly in the tool without custom SQL.

Pattern

When to use

Import data model with Genie Code

Use the /importBI skill to import your data model to Databricks.

Custom SQL with MEASURE()

The tool passes SQL queries to Databricks (for example, using a built-in query or custom SQL option). Most BI tools support this approach.

Pass-through functions in Tableau

You want Tableau to generate the query, so filters, sorts, and table calculations work as usual. You define a calculated field for each measure that wraps it in MEASURE(). See Compare pass-through functions to BI compatibility mode.

Wrapper view

You want to avoid writing SQL in the BI tool. You define a standard view that wraps the metric view with the MEASURE() logic, then point the tool at that view like any other table.

BI compatibility mode

The tool can't pass custom SQL queries to Databricks and instead generates standard aggregations (SUM, COUNT) against measure columns. Databricks rewrites the generated queries to apply the correct measure logic. See Use BI compatibility mode to query metric views for supported scenarios, best practices, and limitations. In Tableau, pass-through functions avoid the aggregation limitations of the rewrite.

Built-in partner integration

The partner has added built-in support for metric views, so measures and dimensions appear directly in the tool without custom SQL.

Compare pass-through functions to BI compatibility mode​

Both pass-through functions in Tableau and BI compatibility mode let report authors build visualizations from metric view measures without writing SQL. The following table compares these approaches:

Behavior

Pass-through functions

BI compatibility mode

Measure evaluation

Tableau sends MEASURE(), and Databricks runs the query as sent.

Databricks rewrites SUM and other aggregations on measure columns.

Connection setup

No extra configuration necessary.

A session configuration in Initial SQL for each connection.

Field setup

One calculated field for each measure.

One SUM wrapper field for each measure, as a best practice.

Aggregation type

Each calculated field is already aggregated, so report authors can't apply an aggregation that changes the result.

Measure columns must use SUM. AVG, Count (Distinct), Median, and other aggregations return incorrect results or errors.

Data preview and extracts

Not supported.

Measure columns show as null.

Behavior

Pass-through functions

BI compatibility mode

Measure evaluation

Tableau sends MEASURE(), and Databricks runs the query as sent.

Databricks rewrites SUM and other aggregations on measure columns.

Connection setup

No extra configuration necessary.

A session configuration in Initial SQL for each connection.

Field setup

One calculated field for each measure.

One SUM wrapper field for each measure, as a best practice.

Aggregation type

Each calculated field is already aggregated, so report authors can't apply an aggregation that changes the result.

Measure columns must use SUM. AVG, Count (Distinct), Median, and other aggregations return incorrect results or errors.

Data preview and extracts

Not supported.

Measure columns show as null.

Use Genie Code to import a Tableau or Power BI file​

Add a Tableau or Power BI file to Genie Code and it replicates your existing data model as a metric view. You can upload a file (.twb, .twbx, .tds, .tdsx, .pbit, or .tmdl) directly into the Genie Code chat, or reference a file stored in a Unity Catalog volume. For help exporting files, see Tableau export documentation or Power BI report templates.

To upload a file in Genie Code chat:

  1. Click Catalog icon..
  2. Click the name of a schema where you want to store the metric view.
  3. Click Create > Metric view.
  4. Enter a name. Then, click Create.
  5. Click the Sparkle genie code icon. Genie Code icon in the top-right corner to open Genie Code.
  6. Click New chat.
  7. Choose Import from a BI tool or type /importBI command to begin importing.
  8. Attach your file from Tableau or Power BI to the chat.

These steps explain how to import your data model to Databricks using a BI tool file. To migrate an entire Power BI or Tableau report into an AI/BI dashboard, see Import BI files using Genie Code instead.

Query a metric view using custom SQL​

All measure evaluations in a metric view query must use the MEASURE aggregate function (or its AGG alias in Databricks Runtime 18.1 and above). You must list each column explicitly because metric views don't support SELECT *. The following query is the canonical pattern and works with any BI tool that supports SQL pass-through:

SQL
SELECT
`Order Month`,
MEASURE(`Total Revenue`),
MEASURE(`Order Count`)
FROM main.sales.orders_metric_view
GROUP BY ALL;

For additional query patterns, including filtering and joining metric view results with other tables, see Query metric views.

Query a metric view through a wrapper view​

If you don't want to write SQL in the BI tool, define a standard view in Unity Catalog that wraps the metric view with the MEASURE() pattern. The view embeds the measure logic, so the BI tool can query it like any other table without custom SQL. This works with any tool that can connect to a Unity Catalog table, including Power BI.

SQL
CREATE VIEW main.sales.orders_report AS
SELECT
`Order Month`,
MEASURE(`Total Revenue`) AS `Total Revenue`,
MEASURE(`Order Count`) AS `Order Count`
FROM main.sales.orders_metric_view
GROUP BY ALL;

Point the BI tool at the wrapper view (for example, main.sales.orders_report) and query it directly. Because a standard view defines a fixed set of dimensions, create a wrapper view for each combination of dimensions your reports need.

Query measures in Tableau with pass-through functions​

Tableau pass-through functions send a SQL expression to Databricks as written. With the RAWSQLAGG functions, you can define each measure as a Tableau calculated field that evaluates MEASURE() on the metric view. Tableau generates the rest of the query, so you don't write custom SQL or maintain wrapper views. Because the generated SQL calls MEASURE() directly, Databricks runs the query as Tableau sends it, with no rewrite and no session configuration.

  1. In Tableau, connect to Databricks with a live connection. On the Data Source tab, add the metric view to the data source. Don't join or relate the metric view to other tables on this tab. Define the joins in the metric view instead. See Joins in metric views. Pass-through functions might not work with published or federated data sources.

  2. For each measure in the metric view, create a calculated field that wraps the measure in MEASURE():

    Text
    RAWSQLAGG_REAL("MEASURE(%1)", [Total Revenue])

    Tableau replaces %1 with the column reference for the first field argument, here the Total Revenue measure.

  3. Drag the calculated fields to the view like any other Tableau measure. Use these fields instead of the original measure columns, which Tableau aggregates with SUM by default.

Choose the RAWSQLAGG function that matches the data type of the measure. Use RAWSQLAGG_INT for integer measures, such as counts, and RAWSQLAGG_REAL for DOUBLE and DECIMAL measures. Use RAWSQLAGG_STR, RAWSQLAGG_DATE, RAWSQLAGG_DATETIME, or RAWSQLAGG_BOOL for string, date, timestamp, and Boolean measures.

When you add Order Month and the Total Revenue calculated field to a view, Tableau generates SQL similar to the following. To check the SQL that Tableau sends, see Query history.

SQL
SELECT
`orders_metric_view`.`Order Month` AS `Order Month`,
(MEASURE(`orders_metric_view`.`Total Revenue`)) AS `Total Revenue`
FROM `main`.`sales`.`orders_metric_view` `orders_metric_view`
GROUP BY 1

Tool-specific guidance​

The following table summarizes the recommended approach for common BI tools.

Tool

Recommended approach

Power BI

Publish the metric view to Power BI as a semantic model (Private Preview). See Connect metric views to Power BI. You can also use the Databricks Power BI connector's Native query option with the MEASURE() pattern in DirectQuery mode. See Native SQL queries.

Tableau

Create a calculated field for each measure with a pass-through function. For a fixed query, use Tableau's Custom SQL connection option with the MEASURE() pattern. To use the measure columns directly, without calculated fields, enable BI compatibility mode from the Initial SQL field in the connection dialog.

Sigma

Use a Sigma dataset backed by custom SQL with the MEASURE() pattern.

Other JDBC or ODBC tools

Use the MEASURE() pattern through the tool's pass-through SQL option. See Work with metric view metadata using the Databricks JDBC Driver for how metric view metadata is exposed to JDBC and ODBC clients.

Tool

Recommended approach

Power BI

Publish the metric view to Power BI as a semantic model (Private Preview). See Connect metric views to Power BI. You can also use the Databricks Power BI connector's Native query option with the MEASURE() pattern in DirectQuery mode. See Native SQL queries.

Tableau

Create a calculated field for each measure with a pass-through function. For a fixed query, use Tableau's Custom SQL connection option with the MEASURE() pattern. To use the measure columns directly, without calculated fields, enable BI compatibility mode from the Initial SQL field in the connection dialog.

Sigma

Use a Sigma dataset backed by custom SQL with the MEASURE() pattern.

Other JDBC or ODBC tools

Use the MEASURE() pattern through the tool's pass-through SQL option. See Work with metric view metadata using the Databricks JDBC Driver for how metric view metadata is exposed to JDBC and ODBC clients.

Built-in partner integrations​

Some partners are adding built-in support for Unity Catalog metric views so that measures and dimensions appear directly in the tool without writing custom SQL. As partners release these integrations, they are documented on the partner pages under Connect to BI partners using Partner Connect.

Additional resources​