Power Query M Code Library

Discover, copy, and customize reusable Power Query M code snippets to speed up your data transformation workflow.

About this library

Every snippet here is a small, working piece of Power Query M — the language behind every query in Power BI, Excel and Power Automate's data flows. Paste one into the Advanced Editor, swap the placeholder names (table, column and file names) for your own, and adjust it to fit your query.

Snippets marked Advanced usually need a bit more context about your data before they'll run as-is; check the notes and requirements under each one first.

Related tools

Once you've written or adapted a query, run it through the Power Query M Formatter to clean up the formatting. Looking for ready-made reports instead of code? Browse the Power BI Dashboard Templates.