How do you add a line break after the first `=` in PowerBI measures when using Tabular Editor c# scripts?

263 Views Asked by At

The FormatDax function in Tabular Editor doesn't put a newline after defining the Measure name. How do you update all the Measure formulas to include a newline after using the FormatDax function?

For example. Turning this...

Count = DIVIDE (
    COUNT ( Tests[Lot] ),
    DISTINCTCOUNT ( Tests[Part Number] )
)

Into this...

Count = 
DIVIDE (
    COUNT ( Tests[Lot] ),
    DISTINCTCOUNT ( Tests[Part Number] )
)
1

There are 1 best solutions below

0
On BEST ANSWER

This took some time to figure out. Leaving a Q&A for easier finding next time.

// C# Script
FormatDax(Model.AllMeasures);

foreach(var measure in Model.AllMeasures)
{
    measure.Expression = Environment.NewLine + measure.Expression;
}