Table of Contents

Rename objects in a Metric View

This how-to demonstrates renaming a Metric View field, and the same pattern applies to every collection in a Metric View: Fields, Measures, Dimensions and Joins.

Note

These how-tos target Tabular Editor 3.26.2 and later, as earlier versions do not support the v1.1 Metric View features shown here. Renaming in place requires Tabular Editor 3.27.0 or later.

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");

Rename a field

Assigning to the object's Name property renames it and keeps the object's other properties (expression, comment, display name, synonyms and format) and its position in the collection.

var view = SemanticBridge.MetricView.Model;

view.Fields["order_month"].Name = "Order Month";

var sb = new System.Text.StringBuilder();
sb.AppendLine("Fields:");
foreach (var field in view.Fields)
{
    sb.AppendLine($"  {field.Name}");
}
Output(sb.ToString());

Output:

Fields:
  product_name
  product_category
  customer_segment
  order_date
  order_year
  Order Month

The collection index updates immediately:

var field = view.Fields["Order Month"];

Naming rules

  • Names must be unique within their collection. Renaming a field to a name another field already uses throws an ArgumentException and leaves the object and the collection unchanged.
  • Name matching is case-insensitive, following Databricks SQL. view.Fields["ORDER MONTH"] finds the field renamed above, and a case-only rename updates the stored name.
  • The rename changes the object model in memory. Serialize the view to write it out.

Next steps

See also