Menu
Stuff by Yuki
  • Home
  • Data Engineering
    • Python
  • Business Intelligence
    • Power BI
    • Tableau
  • Perspectives
  • 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

  • Where I’m Headed in the Next 5 Years
  • Open-Source vs Vendor Data Tools
  • Developing the Habit of Writing
  • How to Inspect and Optimize Query Plans in Python Polars
  • Learn Python Polars with Polars Cookbook

Popular Posts

  • A Running Total Calculation with Quick Measure in Power BI
  • A Complete Guide to Git Integration in Power BI
  • How To Copy And Paste Report Page in Power BI
  • Handling Missing Values in Polars
  • How to Convert String to Date or Datetime in Polars

connect with me

  • LinkedIn
  • Twitter
  • Github
  • Website

Search Articles

©2025 Stuff by Yuki | Powered by SuperbThemes