Skip to main content
Albero Academy

Power Query Deep Dive

Connect, clean, and reshape data with Power Query — the M language, common transformations, parameters, and refresh-friendly patterns.

Chapter 3Power BI17 min readBeginner friendly
  • #Power BI
  • #Power Query
  • #M Language
  • #ETL

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

ActionWhere to click
Promote first row to headersHome → Use First Row as Headers
Change column typeright-click column → Change Type
Remove rowsHome → Remove Rows → Remove Top Rows
Remove duplicatesHome → Remove Rows → Remove Duplicates
Filter rowsclick the dropdown on the column header
Replace valuesright-click column → Replace Values
Pivot / UnpivotTransform → Pivot Column / Unpivot
Split columnright-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.

M · sales.csv pipeline
let
Source = 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])
)
in
AddedMonth

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.
merge in M
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.SelectRows as 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

  1. 01Power Query is the ETL layer — visual on top, M language underneath, push-down friendly.
  2. 02Set column types early; auto-detect doesn't survive locale changes.
  3. 03M is case-sensitive: Table.SelectRows works, table.SelectRows errors.
  4. 04Append = UNION ALL; Merge = JOIN with all the join-kind variants.
  5. 05Parameters & functions make queries reusable across files & environments.
  6. 06Filter early; disable load on staging queries; avoid Excel as a long-term source.