If you are working with DAX and do more than single-line statements, you will frequently find yourself wishing for a powerful editor with proper syntax highlighting. Below I explain how to use Notepad++ for that purpose. While I use DAX mostly in Power BI, it of course works just as well with other environments.
If you prefer watching over reading, check out the short video below. In it, I use DAX as an example. But it works just the same for M, of course.
First Things First
- This guide is based on the 64-Bit Notepad++ version 8.4.2. You can always download the latest version of Notepad++ here.
- The same process works with the files for PowerQuery (M) over here.
To the right, you can download the custom language XML files for easy import into Notepad++ and further customization.
Follow the instructions below to
- enable syntax highlighting
- enable auto-completion
- modify the syntax colors to your liking
Get The Files
Extract the received ZIP archive and open the folder location in your file explorer. Make sure there is an “m.xml” file and an “AutoComplete” folder.
I am aware that the screenshots show DAX, just select M instead. The process remains the same.
To import the file,
- start Notepad++,
- click on Language, Define your Language, Import,
- navigate to the file and click Open.
- Close the Define your Language dialog.
Make sure to click Language again and select DAX from the list. Only then it will be applied to the file you opened.
If you don’t see DAX in the language menu right away, you may have to restart Notepad++.
This will give you syntax highlighting. If you want to have the auto-complete functionality, you need to
- navigate to the extracted folder
- enter the “AutoComplete” folder
- copy the file “m.xml” from the AutoComplete folder to the folder “autoCompletion” inside the Notepad++ program directory. In my case this is “C:\Program Files\Notepad++\autoCompletion“
- You will get a warning, requiring Administrator permissions.
- Confirm the warning and restart Notepad++
Modifying The Colors
I tried to pick colors that work equally well with the light and dark theme of Notepad++. However, colors that work well for me, might not be that great for you.
Fortunately, you can adapt them very easily. In Notepad++ click on Language, User Defined Language, Define your Language.
Select M from the User Language drop-down:
Use the tabs to find the elements you want to modify:
- Folder & Default
- Comment & Number
- Operators & Delimiters
Click on the Styler button and adjust any attributes you want
- Foreground color
- Background color
- Fixed some formatting issues
- Created completely new XML files for syntax highlighting and auto-completion
- Adjusted formatting to work with dark and light mode
- Made the syntax highlighting case-insensitive
- Separated AutoComplete from syntax highlighting to work with the new version of Notepad++