# Format all DAX in your model at once with Tabular Editor

> We look at how to format all DAX in Power BI datasets at once. With the push of a button your DAX will be formatted using these C# scripts! Save them as macros and never waste time formatting again.

- URL: https://data-goblins.com/format-all-dax
- Author: Kurt Buhler
- Published: 2021-12-28
- Topic: Tools and automation

# USE TABULAR EDITOR TO FORMAT ALL DAX IN YOUR MODEL

*…turn them into macros to **format all your DAX with the push of a button.** Easy!*

---

## CLICK TO DOWNLOAD C# SCRIPTS FOR TABULAR EDITOR

---

### C# Scripts in Tabular Editor

A handy feature of Tabular Editor is the ability to create C# scripts to **simplify & automate basic development tasks.** This is a feature available in both Tabular Editor 2 (TE2; free version) and Tabular Editor 3 (TE3; licensed version), though in TE3 these scripts can be turned into macros for easier repeated use in the GUI.

One such task that can be easily automated is the **formatting of DAX code in the data model**. Particularly upon inheriting a data model from someone else, formatting the DAX is often the first thing we tend to do. This is already super easy in TE and can be done with the push of a button. But if you have a lot of measures, calculation groups, calculated columns & tables… it gets tedious.

<figure class="dg-figure"><img src="https://images.data-goblins.blog/2025/12/format-all-dax-new-csharp-script.png" alt=" C# Scripts in TE (shown: TE3) "><figcaption>C# Scripts in TE (shown: TE3)</figcaption></figure>

For measures, there is [a method described for doing this in the TE docs](https://docs.tabulareditor.com/te2/Useful-script-snippets.html#format-dax-expressions), and some other good blog posts [like this one from Ed Hansberry](https://www.ehansalytics.com/blog/2021/7/1/quickly-format-all-dax-code-in-tabular-editor) which sent me into the rabbit hole of trying out C# scripting in TE. Since then it’s been a nice thing to experiment with to streamline my Power BI workflow. I had never used C# before so it was interesting to use it as a new avenue for learning.

### From Calculation Groups to Columns: Format all the things!

I needed to be able to format DAX for a lot of calculation groups, as well as other objects. So I took what I learned from others and made the below scripts to format & count the objects, returning a pop-up upon execution of the script / macro. The below scripts work for:

![](https://images.data-goblins.blog/2025/12/format-all-dax-format-all-things.png)

- [Measures](https://data-goblins.com/power-bi/format-all-dax/#format-measures)
- [Calculation Items in Calc. Groups](https://data-goblins.com/power-bi/format-all-dax/#format-calc-groups)
- [Calculated Tables*](https://data-goblins.com/power-bi/format-all-dax/#format-calc-tables)
- [Calculated Columns*](https://data-goblins.com/power-bi/format-all-dax/#format-calc-columns)
- [All Objects (Format All Things)*](https://data-goblins.com/power-bi/format-all-dax/#format-all-things)

Hope they are useful. I still might see if I can make one for Roles & Detail Row Expressions.

***[*As described in the TE docs*](https://docs.tabulareditor.com/te3/desktop-limitations.html#data-modeling-operations)*, TE has limitations in altering the model in Power BI Desktop. It is thus not possible with a connection to Power BI Desktop to format DAX for Calc. Tables & Columns unless you enable “unsupported features”, which is not recommended. This works fine if you are connected via XMLA endpoint.*

---

### How to use the scripts

*Note: While I wrote & use these scripts in Tabular Editor 3, they should also work in Tabular Editor 2.*

<figure class="dg-figure"><img src="https://images.data-goblins.blog/2025/12/format-all-dax-run-script.png" alt=" Executes the code. "><figcaption>Executes the code.</figcaption></figure>

- Open Tabular Editor
- Create a new C# script (file > new… > C# script)
- Copy & paste the code below
- Select “Run Script” (Keyboard Shortcut F3)
- (TE3) Select “Save as Macro…” if you want to make it easily re-usable.

---

<figure class="dg-figure"><img src="https://images.data-goblins.blog/2025/12/format-all-dax-before-formatting.jpg" alt=" Before formatting "><figcaption>Before formatting</figcaption></figure>

<figure class="dg-figure"><img src="https://images.data-goblins.blog/2025/12/format-all-dax-measures-infobox.png" alt=" Info pop-up "><figcaption>Info pop-up</figcaption></figure>

<figure class="dg-figure"><img src="https://images.data-goblins.blog/2025/12/format-all-dax-after-formatting.png" alt=" After formatting "><figcaption>After formatting</figcaption></figure>

However if you look in Power BI, you see that the measure now starts next to the definition. Depending on the length of the first line of DAX code, this can be distracting, so it’s sometimes preferable to include a new line at the start when formatting. [This is also described in Ed’s blog post.](https://www.ehansalytics.com/blog/2021/7/1/quickly-format-all-dax-code-in-tabular-editor)

<figure class="dg-figure"><img src="https://images.data-goblins.blog/2025/12/format-all-dax-powerbi-after.png" alt=" The first line is together with the measure name after formatting with the simple syntax. "><figcaption>The first line is together with the measure name after formatting with the simple syntax.</figcaption></figure>

### **Format all Measures** (Long-Line format with leading new line)

Another advantage of this syntax is you can easily adjust it to format all measures with short-line instead of long-line format. To format in short-line you just have to add one argument - **shortFormat: true**

### **Format all Measures** (Short-Line format with leading new line)

---

The below code will format & count calculation items in the model. This can be done in both Power BI Desktop & cloud-published data models, so I like to have this done together with the measure formatting, usually, in a single macro.

---

> **Note:** Will not work on Power BI Desktop unless “unsupported features” are enabled, which is not recommended.

---

> **Note:** Will not work on Power BI Desktop unless “unsupported features” are enabled, which is not recommended.

---

*Thanks to Mateusz Mossakowski for informing me about the deprecation of FormatDax().*

---

The below script (which you can download by clicking on the button) is a combination of all the above.

Keep in mind again that formatting Calculated Tables & Calculated Columns will not work with Power BI desktop unless you enable “unsupported features”, which is not recommended. It does work perfectly fine when connecting to a model using the XMLA endpoint.

<figure class="dg-figure"><img src="https://images.data-goblins.blog/2025/12/format-all-dax-format-all-things.png" alt=" Get FAT - format all things! "><figcaption>Get FAT - format all things!</figcaption></figure>
