Power Query is the ETL layer underneath Power BI, Excel, and Microsoft Fabric. Every Power BI dataset starts here — and almost every dashboard performance problem can be traced back to bad Power Query habits. This chapter is the deep dive most learners skip and later regret.
Why Power Query?
- Repeatable. Steps are recorded as code. Refresh re-runs them; new rows flow through automatically.
- Visual. 90% of common transformations are point-and-click — no need to learn M for daily work.
- Connector-rich. 100+ connectors. SQL, REST APIs, SharePoint, Salesforce, Excel, JSON, all behave the same way once loaded.
- Push-down friendly. When connected to a database, Power Query pushes filters and joins back as native SQL — fast, even on huge tables.
The editor tour
Click Transform Data on the Power BI ribbon to open the Power Query Editor. The four panes:
- Queries pane (left) — every query in the file.
- Preview grid (centre) — first 1,000 rows of the current query.
- Query Settings (right) — the step list. Click any step to time-travel.
- Formula bar (top) — shows the M expression for the current step.
Common transformations
| Action | Where to click |
|---|---|
| Promote first row to headers | Home → Use First Row as Headers |
| Change column type | right-click column → Change Type |
| Remove rows | Home → Remove Rows → Remove Top Rows |
| Remove duplicates | Home → Remove Rows → Remove Duplicates |
| Filter rows | click the dropdown on the column header |
| Replace values | right-click column → Replace Values |
| Pivot / Unpivot | Transform → Pivot Column / Unpivot |
| Split column | right-click column → Split Column |
A taste of the M language
Behind the visual editor, every step is a line of M. Reading it is enough; you rarely need to write it from scratch.
letSource = Csv.Document(File.Contents("C:\data\sales.csv"), [Delimiter=","]),PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),ChangedTypes = Table.TransformColumnTypes(PromotedHeaders, {{"OrderID", Int64.Type},{"OrderDate", type date},{"Revenue", type number}}),FilteredRows = Table.SelectRows(ChangedTypes, each [Revenue] > 0),AddedMonth = Table.AddColumn(FilteredRows,"Month",each Date.MonthName([OrderDate]))inAddedMonth
Merge & Append queries
- Append — stack two tables vertically (same columns). Like SQL
UNION ALL. - Merge — join two tables on a key. Like SQL
JOIN. Choose the join kind: Inner, Left Outer, Right Outer, Full Outer, Anti.
Merged = Table.NestedJoin(Sales, {"CustomerID"},Customers, {"CustomerID"},"CustomerInfo",JoinKind.LeftOuter)
Parameters & functions
Parameters let you swap values at refresh time — e.g., switch from a dev database to prod without editing the query.
- Manage Parameters → New Parameter — define a typed parameter (text, date, etc.) with a default.
- Reference the parameter in any step instead of a hard-coded value.
- Convert a query to a function (right-click → Create Function) to apply it across many files.
Refresh-friendly patterns
- Disable load on staging queries. If a query is just an intermediate step (e.g., a lookup), right-click → Disable Load. Saves memory.
- Filter early. Push
Table.SelectRowsas close to the source as possible — Power Query may push it down to SQL. - Avoid wide unpivots in fact tables. Reshape in the warehouse if you can; do it in PQ only if you must.
- Don't use Excel as a source for production reports. Switch to a database or dataflow once the analysis is real.
Key takeaways
- 01Power Query is the ETL layer — visual on top, M language underneath, push-down friendly.
- 02Set column types early; auto-detect doesn't survive locale changes.
- 03M is case-sensitive: Table.SelectRows works, table.SelectRows errors.
- 04Append = UNION ALL; Merge = JOIN with all the join-kind variants.
- 05Parameters & functions make queries reusable across files & environments.
- 06Filter early; disable load on staging queries; avoid Excel as a long-term source.
