Sub topic 1
What Power Query Does and Why It Beats Manual Cleanup
Prerequisites
This chapter assumes you can work with Excel worksheets and tables, and that you know the basic data types: text, number, and date. You should also be able to open and save Excel workbooks and CSV files. You do not need to know any code.
What Power Query is
Power Query is the Get & Transform feature in Excel. It connects to a data source, applies a series of transformations, and loads the result into your workbook. It is on the Data tab, in the Get & Transform Data group.
The key idea is that Power Query does not change your source data. It records each transformation as a step. When the source changes, you refresh the query and Excel replays the steps on the new data.
Manual cleanup versus Power Query
Manual cleanup means you fix the data by hand with Find and Replace, formulas, filters, and copy and paste. It works once. The next month, new data arrives with the same problems, and you repeat every action from memory.
| Question | Manual cleanup | Power Query |
|---|---|---|
| Can you repeat it next month? | Only if you remember every action | Yes, with one Refresh |
| Can you see what was done? | No | Yes, in the Applied Steps list |
| Is the source data changed? | Often | No |
| Can you undo one earlier action? | Rarely | Yes, edit or delete that step |
| Does it handle large files? | Slowly | Better, as it avoids worksheet formulas |
How the process works
Every query follows the same path: connect, transform, load.
The Refresh arrow is the main benefit. You build the cleanup once, and every later refresh repeats it.
A first look at a recorded step
Each step is stored as a line of code in a language called M. You rarely need to write it yet, but it helps to see one. This query reads an Excel table named SalesRaw, sets column types, and cleans the Region text.
let
Source = Excel.CurrentWorkbook(){[Name="SalesRaw"]}[Content],
Typed = Table.TransformColumnTypes(Source, {{"Date", type date}, {"Amount", type number}}),
Trimmed = Table.TransformColumns(Typed, {{"Region", each Text.Trim(Text.Clean(_)), type text}})
in
TrimmedEach line after let is one step, and each step takes the result of the one before it. Source loads the table, Typed sets the types, and Trimmed removes extra spaces and non-printing characters. The in line names the step that becomes the final result.
When to use it
Power Query fits best when:
- the same cleanup is needed again and again
- data comes from several files or sources
- the source has problems such as extra spaces, wrong types, blank rows, or a cross-tab layout
It is not the best choice for a one-off fix of a few cells. Editing those by hand is faster.
Common mistakes
- Editing the loaded table by hand. A refresh overwrites manual changes to a loaded table. Change the query instead.
- Expecting live updates. A query updates only when you refresh it, unless you set up automatic refresh.
- Moving or renaming the source. If a file path or table name changes, the first step fails.
Exercise
A colleague cleans a monthly export by hand with Find and Replace and filters. Name two reasons Power Query would serve them better.
Show answer
The cleanup is recorded as Applied Steps, so a single Refresh repeats it on next month's file without redoing the work. The steps are also visible and editable, and the original source data stays unchanged.
Exercise
In the sample query, which step removes extra spaces from the Region column?
Show answer
The Trimmed step, which uses Text.Trim and Text.Clean.