You can use Notepad++ to write and edit Power Query M code, but it does not understand the language out of the box. To get syntax highlighting and a workable editing experience, you install a user-defined language (UDL) for M, then paste your queries in, format them, and copy them back into Power Query. There is no official Notepad++ plugin from Microsoft for M, so the practical route is a UDL XML file plus Notepad++'s built-in formatting tools. This guide covers that setup, how to move code in and out of Power Query safely, and the mistakes that cost people the most time.
What You'll Need
- Notepad++ installed from the official notepad-plus-plus.org download page (the portable build works too).
- A Power Query M user-defined language file (a .xml UDL). These are shared by the community; search for "Power Query M UDL Notepad++" and download one from a source you trust. There is no Microsoft-published UDL, so treat any download as third-party code and scan it before importing.
- A Power Query editor to test code: Excel (Data > Get Data), Power BI Desktop (Home > Transform data), or the Power Query editor in Fabric. The M engine is the same, but the host application's menus differ.
- Optional: a JSON or XML formatter plugin from Notepad++'s Plugin Admin if you also edit query metadata files. Not required for M itself.
Step-by-Step
- Open Notepad++ and confirm your version. Go to Help > About Notepad++ and note the version. UDL import works the same across recent versions, but menu labels can differ slightly by version and by whether you use the 32-bit or 64-bit build.
- Import the M language definition. In Notepad++, open Language > User Defined Language > Define your language. Click Import, select the M UDL .xml file you downloaded, and confirm. The language should now appear under the Language menu, usually near the bottom of the list. If the import fails, the file is probably not a UDL XML or is corrupted; re-download it rather than editing it by hand.
- Set M as the default for .m and .pq files (optional). Still in Define your language, use the Ext. field to associate the UDL with .m and .pq. This makes Notepad++ apply highlighting automatically when you open saved query files.
- Get your M code out of Power Query. In the Power Query editor, open the Advanced Editor (Home > Advanced Editor in most hosts; the label is consistent across Excel and Power BI). Select all the code, copy it, and paste it into a new Notepad++ tab. Do not retype it: M is case-sensitive and a single wrong capital breaks a query.
- Turn on the features that matter for M. Under View, enable Word wrap and Show Symbol > Show All Characters so you can see line endings and tabs. M is whitespace-tolerant, but stray non-breaking spaces pasted from web pages cause errors that are hard to spot. Also enable View > Show Symbol > Show Whitespace and Tab.
- Use Find and Replace for bulk edits. Press Ctrl+H. Common jobs: rename a step (for example change every "Changed Type" to "Changed Type Final"), swap a server name, or fix a column name across a long query. Tick Match case, because M identifiers are case-sensitive. Use Replace All only after a Find All confirms the match count you expect.
- Format for readability. Notepad++ has no built-in M formatter. The practical approach is manual: put each step on its own line, align the commas in record and list literals, and keep the
letandinkeywords at the left margin. If you use a community M formatter, run it outside Notepad++ and paste the result back, then re-check it in the Advanced Editor. - Use column editing for repetitive lists. Hold Alt and drag to create a vertical selection, or use Edit > Column Editor to insert the same text on many lines at once. This is the fastest way to build long lists of column names or field references.
- Paste back and validate. Copy the edited code, return to the Advanced Editor, select all, paste, and click Done. Power Query parses the code immediately. If it errors, the message usually names the line and token; go back to Notepad++ and fix that line rather than rewriting the query.
- Save a plain-text backup. Save the .m file somewhere versioned (a Git repo or a dated folder). Keep the Power Query copy as the source of truth, because the Advanced Editor is what actually runs.
Common Mistakes
- Pasting smart quotes. Word processors and web pages turn straight quotes into curly ones. M only accepts straight double quotes. Use Search > Replace with Match case and search for the curly characters, or paste through a plain-text editor first.
- Losing the final newline or trailing comma rules. M lists and records allow a trailing comma, but a missing comma between steps is the single most common parse error. Check each step's closing parenthesis and comma.
- Editing a step name but not its reference. If you rename a step, every later step that calls it must change too. Use Find All to count references before replacing.
- Assuming highlighting means validation. A UDL only colours text; it does not check syntax. Always validate in the Advanced Editor.
- Downloading UDLs from random file hosts. A UDL is XML, but treat unknown downloads with suspicion. Prefer sources with visible history and scan the file.
Tips
- Keep a scratch tab with the standard
let ... inskeleton so you can start new queries quickly. - Use Notepad++'s session feature (File > Save Session) to keep all your query files open across restarts.
- For long queries, use the Function List panel only if your UDL defines function patterns; otherwise it stays empty and that is normal.
- Compare two versions of a query with Plugins > Compare (install via Plugin Admin) to see exactly what changed between edits.
- When a query works, paste the final M into a comment block in your workbook or documentation so the logic survives even if the query is deleted.
Troubleshooting
If the M language does not appear after import, close and reopen Notepad++, then re-import. If highlighting appears but is wrong (keywords not coloured), the UDL's keyword lists are incomplete; that is cosmetic and does not affect the code. If pasted code fails in the Advanced Editor with a token error, check for curly quotes, non-breaking spaces, and missing commas first. If the Advanced Editor rejects code that looks correct, simplify: comment out steps with // one at a time until the error moves, which isolates the bad step. If Notepad++ crashes on a very large query, open the file with word wrap off and avoid Replace All across the whole document. If you cannot find a UDL you trust, skip highlighting entirely: plain-text editing with careful formatting still works, and validation happens in Power Query anyway.
Frequently Asked Questions
Does Notepad++ officially support Power Query M?
No. There is no Microsoft plugin or built-in M language in Notepad++. Support comes from community user-defined language files, which provide highlighting only, not validation.
Can Notepad++ run or test M code?
No. M runs inside Power Query in Excel, Power BI, or Fabric. Notepad++ is only an editor; you must paste code back into the Advanced Editor to test it.
Why does my code fail after pasting from Notepad++?
Almost always curly quotes, non-breaking spaces, or a missing comma between steps. Show all characters in Notepad++ and check the line the error names.
Is there a Power Query formatter for Notepad++?
Not a reliable built-in one. Format manually or use an external M formatter and paste the result back, then re-validate in Power Query.
Can I edit .pq files directly in Notepad++?
You can open and edit them as text, but the host application is the source of truth. Editing exported files does not change a query already loaded in Excel or Power BI.