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 |
|---|---|
Use the | |
The tool passes SQL queries to Databricks (for example, using a built-in query or custom SQL option). Most BI tools support this approach. | |
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 | |
You want to avoid writing SQL in the BI tool. You define a standard view that wraps the metric view with the | |
The tool can't pass custom SQL queries to Databricks and instead generates standard aggregations ( | |
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 | Databricks rewrites |
Connection setup | No extra configuration necessary. | A session configuration in Initial SQL for each connection. |
Field setup | One calculated field for each measure. | One |
Aggregation type | Each calculated field is already aggregated, so report authors can't apply an aggregation that changes the result. | Measure columns must use |
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:
- Click
.
- Click the name of a schema where you want to store the metric view.
- Click Create > Metric view.
- Enter a name. Then, click Create.
- Click the
Genie Code icon in the top-right corner to open Genie Code.
- Click New chat.
- Choose Import from a BI tool or type
/importBIcommand to begin importing. - 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:
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.
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.
-
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.
-
For each measure in the metric view, create a calculated field that wraps the measure in
MEASURE():TextRAWSQLAGG_REAL("MEASURE(%1)", [Total Revenue])Tableau replaces
%1with the column reference for the first field argument, here theTotal Revenuemeasure. -
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
SUMby 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.
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 |
|---|---|
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 | |
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 | |
Use a Sigma dataset backed by custom SQL with the | |
Other JDBC or ODBC tools | Use the |
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.