Menu
Stuff by Yuki
  • Home
  • Python
  • Power BI
  • Tableau
  • Community
    • Makeover Monday
    • Workout Wednesday
  • About
  • Contact
Stuff by Yuki

Format All DAX Measures at Once

Posted on April 7, 2023

There are tools that help you format your DAX code such as Tabular Editor and daxformatter.com. They can only format your DAX one by one. Have you ever found yourself doing that before? Then this blog post is for you. With C# scripting in Tabular Editor, you can format your DAX measures all at once!

Format All DAX Measures at Once with Tabular Editor

If you haven’t done any C# scripting in Tabular Editor, this can be a good introduction for you. There is a tab in Tabular Editor where you can write some C# code to do model operations. You can save your snippets so that you use can them not only in one report, but also in many others.

1. You switch to another tab called “C# Script”:

2. Copy and paste the following C# code:

Copy Copied Use a different Browser

foreach (var m in Model.AllMeasures) 
{
    m.FormatDax();
}

What the code is doing is to go through each measure and format it one by one. How simple is that!

That’s pretty much it, but there is one thing you need to be careful when formatting DAX through C#. There are a few other ways to accomplish the same, but as the documentation says, avoid writing the code like this:

The followings are the alternatives to the deprecated version:

  1. m.FormatDax();
  2. Model.AllMeasures.FormatDax();
  3. FormatDax(m);
  4. FormatDax(Model.AllMeasures);

These alternatives essentially batch all the FormatDAX() function calls into one request.

Conclusion

With C# scripting in Tabular Editor, you can easily format all your DAX measures at once. You can do a lot more stuff with C# scripting, and that can definitely something can separate you from other Power BI developers.

Github repo

Tabular Editor documentation

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to Convert String to Date or Datetime in Polars
  • Aggregations Over Multiple Columns in Polars
  • DuckDB with Polars, Pandas, and Arrow
  • Read from and Write to Amazon S3 in Polars
  • Handling Missing Values in Polars

Popular Posts

  • A Running Total Calculation with Quick Measure in Power BI
  • How To Copy And Paste Report Page in Power BI
  • How to Fill Dates Between Start Date and End Date in Power BI (Power Query)
  • Year-Over-Year Calculation: Time Intelligence in Power BI
  • Network Visualizations in Python

connect with me

  • LinkedIn
  • Twitter
  • Github
©2023 Stuff by Yuki | Powered by SuperbThemes & WordPress
x
x