Patterns

Practical M recipes — real-world solutions to common problems, going beyond what function docs alone can teach.

Beginner

Intermediate

Cross-Query Lookup (VLOOKUP in M)
Look up values from one table in another — the M equivalent of VLOOKUP — using Table.NestedJoin or direct list lookup patterns.
Intermediate
Custom Function Reuse
Define M functions once and call them across multiple queries — eliminating copy-paste logic, improving maintainability, and applying consistent transformations at scale.
Intermediate
Building a Date Dimension Table
Generate a complete date table in M with year, month, quarter, week, and fiscal period columns — no external data source needed.
Intermediate
Dynamic Column Selection
Select table columns by name at runtime using a list variable instead of hardcoding column names.
Intermediate
Error Recovery in Table Columns
Use try/otherwise to recover from errors cell-by-cell in a column, preserving rows that would otherwise fail and optionally capturing the error message.
Intermediate
Fuzzy Text Matching
Match records across tables when values aren't identical — handling typos, spacing, and case differences.
Intermediate
Expanding Nested JSON and XML
Parse and flatten nested JSON objects, arrays, and XML structures returned by APIs using iterative expansion with Table.ExpandRecordColumn, Table.ExpandListColumn, and Xml.Document.
Intermediate
Pivot and Unpivot
Reshape tables between wide and long format using Table.Unpivot, Table.UnpivotOtherColumns, and Table.Pivot — including null handling, aggregation, and dynamic column lists.
Intermediate
Query Performance Optimization
Diagnose and fix slow Power Query M queries by preserving query folding, buffering intermediate results, consolidating transform steps, and knowing when to push work back to the source system.
Intermediate
Running Totals and Cumulative Calculations
Compute cumulative sums, running counts, and other window-style calculations in M using List.Generate or List.Accumulate — no built-in window function needed.
Intermediate
Table Joins
Combine tables on shared keys using Table.NestedJoin and Table.ExpandTableColumn — covering left outer, inner, right outer, full outer, anti-join, and multi-column joins.
Intermediate
Text Parsing Patterns
Extract, split, and transform text in M using Text.* functions — parsing delimited strings, extracting substrings, and cleaning messy data without regular expressions.
Intermediate

Advanced