Power Query

Clean a messy export in six steps

Power Query is where a report is won or lost. Six actions — remove, filter, retype, unpivot, merge, group — turn a spreadsheet held together by merged cells into a table a model can use. Every step is recorded, so next month's file cleans itself.

No code requiredRepeatable on refreshBeginner level
P
Six actionsThe order matters
12 min read
1 · Remove columnsnarrow
2 · Filter rowssmaller
3 · Change typescorrect
4 · Unpivottall
5 · Merge / appendjoined
6 · Group bysummarised
WhereTransform data → Power Query
RecordedEvery click is a step
Runs onRefresh, not on render
OutputOne clean table
The six actions

What each one is for, and when it is the wrong tool

1 · Remove columns — narrow before anything else

Select the columns you need, then Home → Remove Columns (or right-click → Remove Other Columns). Do this first: every later step runs on fewer columns and the file loads faster. A 40-column export usually needs six.

Wrong when: you remove a column a later step needs as a join key. Keep keys until the merge is done.

2 · Filter rows — drop what the report never shows

Use the column header dropdown to exclude test orders, closed regions or total rows. If the file has a summary row at the bottom, filter it out here or every SUM later will be double.

Wrong when: the business may later ask about the rows you filtered. If so, keep them and filter in DAX instead — a filter in Power Query is irreversible for everyone downstream.

3 · Change types — after filtering, never before

Right-click the column header → Change Type. Dates as dates, amounts as decimal numbers, IDs as text (leading zeros matter). The ABC/123 indicator in the header tells you what Power Query currently thinks a column is.

Why not first: changing a date column to Date before filtering can turn "N/A" and "总计" rows into errors, which then spread through the query as Error values.

4 · Unpivot — turn month columns into rows

Exports love one column per month. Select the columns that identify a row (product, region), then Transform → Unpivot Other Columns. You get Date, Attribute, Value — a tall table that a date table can filter.

Before:  Product | Jan | Feb | Mar
After:   Product | Month | Sales
         A       | Jan   | 120
         A       | Feb   | 98

Pivot is the reverse and rarely what you want: it hard-codes columns, so next January's data has nowhere to go.

5 · Merge and append — one joins, the other stacks

Merge adds columns from another table on a matching key (like VLOOKUP, but for whole tables). Append stacks tables with the same columns (like copy-paste from several monthly files).

Prefer loading a folder over appending by hand: Get Data → Folder reads every file in a directory and appends them with the same steps. Next month's file just needs to be dropped in.

6 · Group by — summarise only when the model needs it

Transform → Group By produces a summary table in the query. Usually you do not need this: DAX measures aggregate far more flexibly. Group by only when you are building a small dimension table (distinct products, distinct regions) or an aggregate table for performance.

Wrong when: you group the fact table and lose the row-level detail a slicer would need.

Order matters

Why this sequence, and not another

OrderReason
Remove → filter → retypeFewer columns and rows means less work for type conversion, and no junk rows turning into errors.
Unpivot before mergingUnpivot changes the shape; merging into a shape you are about to change means doing the merge twice.
Merge last for lookupsA merge expands a lot of columns; removing them afterwards is easy, doing it before is not.
Group by only at the endIt discards detail. Anything that needs row-level detail must happen before it.
Mistakes

Five habits that break a query six months later

Hard-coded file paths

C:UsersyouDesktopsales.xlsx breaks the moment the report is refreshed on another machine. Use a parameter, or load the folder instead of the file.

Cleaning in Excel first

Manual cleanup is not recorded. If a colleague re-exports the file, the work is gone. Do it in Power Query so it repeats on refresh.

Deleting the Applied Steps

Each step is a safety net: click one to see the data at that moment. Deleting steps to "clean up" removes that debugging path.

Keeping every column "just in case"

Unused columns cost memory and refresh time, and they clutter the field list so the model is harder to navigate.

Loading before checking

Use Close & Apply only after reviewing the last step's output. Loading a broken query writes a broken table.

No column-name strategy

Rename columns to what the report says — Amount, OrderDate — before loading. Renaming later means fixing every measure that referenced the old name.

FAQ

Common questions about Power Query

Do I need to know M code?

No for these six actions — the interface records them. M matters when you need a custom column with logic the UI cannot express, or when you want to parameterise a path.

Does Power Query run every time I click a slicer?

No. It runs on refresh and stores the result in the model (Import mode). Query performance affects refresh time, not click response.

Should I clean data in Power Query or in DAX?

Shape and type fixes belong in Power Query. Calculations that must respond to filters belong in DAX. Cleaning in DAX means repeating the logic in every measure.

How do I handle a file that changes column order every month?

Select columns by name rather than by position, and use "Unpivot Other Columns" instead of listing columns. If headers change names, load the folder and promote headers per file.

Why does my date column show errors?

Usually a type conversion on text that is not a date (totals rows, "N/A", locale formats like 01/02/2026 meaning different days). Filter those rows out before changing the type, and set the locale explicitly in Change Type → Using Locale.

Next

Clean table, then a model that can use it

Star schema in five steps

Split the cleaned table into fact and dimensions, and add the date table that time intelligence needs.

Read the star schema guide

Six DAX measures

Once the model is clean, these are the measures most reports actually need.

Read the DAX guide