Import a Metric View from a file
This how-to demonstrates importing a Metric View into a Tabular model directly from a YAML file.
Note
These how-tos target Tabular Editor 3.26.2 and later. Earlier versions do not support the v1.1 Metric View features shown here.
Get the sample Metric View
Save the sample Metric View (below) to a local file.
You will need to replace the placeholder in the example below with this path.
For this how-to, specifically, you only need to save the file; you do not need to run Load or Deserialize.
Load the sample Metric View for these code samples
Before starting, make sure you have Tabular Editor 3 open and have a Tabular model opened, or create a new model.
This how-to uses a sample e-commerce Metric View representing sales data with three dimension tables (product, customer, date) joined to a fact table (orders). Use either method below to load it (either "download and load" or "copy and deserialize"), then follow along with the rest of this how-to. You can run either command in the same C# script as the rest of this example, or you can run it first, in its own C# script, and the rest of the example in its own C# script.
Download sample-metricview.yaml
and load it by path:
SemanticBridge.MetricView.Load("C:/path/to/sample-metricview.yaml");
Import from file
ImportToTabularFromFile loads the YAML from disk and imports it into the open model in one step.
Update the placeholder in the script below (<PLACEHOLDER>) with the path where you saved the YAML.
The Databricks hostname and HTTP path are used to build the M partition expressions; for a quick test you can pass placeholder values and fix them before refreshing data.
var success = SemanticBridge.MetricView.ImportToTabularFromFile(
"<PLACEHOLDER>",
Model,
"your-workspace.azuredatabricks.net",
"/sql/1.0/warehouses/abc123def456",
out var diagnostics
);
var sb = new System.Text.StringBuilder();
sb.AppendLine(success ? "Import successful!" : "Import failed.");
sb.AppendLine($"Diagnostics: {diagnostics.Count}");
Output(sb.ToString());