Power Query M Formatter
Paste M code, click Format. Runs in your browser.
Input
Formatted code
Why format your M code?
Power Query queries written through the Power BI or Excel interface often end up as long, unindented steps. Consistent formatting makes each transformation step easy to scan, review and compare in version control, and it makes mistakes like a missing comma or bracket much easier to spot.
This formatter uses Microsoft's open-source Power Query formatter, so the output follows the same rules as Microsoft's own tooling. Your code is processed locally in your browser and is never sent to a server.
How to use this formatter
You don't need to install anything or sign up. Just bring your M code from Power BI or Excel, paste it in, and copy the result back.
- Open the Advanced Editor for your query in Power BI Desktop or Excel (right-click the query in the Queries pane and choose Advanced Editor).
- Copy all the M code and paste it into the Input box on the left.
- Click Format.
- Copy the result from the Formatted code box and paste it back into the Advanced Editor, replacing the original code.
Frequently asked questions
Is my code uploaded anywhere?
No. Everything runs locally in your browser using JavaScript. Your M code never leaves your device or touches a server, so it's safe to paste in queries that reference internal file paths, server names or other sensitive details.
Does it work with Excel Power Query too?
Yes. Excel's Power Query editor uses the same M language as Power BI, so formatting works identically for both. Paste code from either one.
Does it change what my query does?
No. The formatter only changes spacing, indentation and line breaks. The logic and results of your query stay exactly the same.
Can I format DAX here?
No. This tool only understands Power Query M code, not DAX. DAX is a separate language used for measures and calculated columns. Use the DAX Formatter for that instead.
What formatting rules does it follow?
It uses Microsoft's own open-source Power Query formatter, so the output follows the same conventions as Microsoft's official tooling, rather than a custom style invented for this site.
Is there a limit on how much code I can format?
There's no hard limit built into the tool, but very large queries may take a moment longer since everything runs in your browser rather than on a server.
Related tools and resources
Looking for code to adapt? See the Power Query M topic page or browse the Power Query M Code Snippets, for example Remove Duplicate Rows. Need a date table? Generate one as Power Query M.