Excel course · Lesson 24 of 34
Power Query basics: import, clean, append, merge, refresh
Use Power Query to import CSV files, folders and tables, record cleaning steps once, append and merge queries, and refresh everything with one click.
If you regularly receive the same kind of file, a weekly sales export, a monthly bank statement, an HR extract, and spend an hour cleaning it each time, Power Query is for you. It records every cleaning step you take. Next time, you drop in the new file and click Refresh: all steps run again in seconds. Power Query is built into Excel 2016 and later on Windows under Data › Get & Transform Data, and in Microsoft 365 for Mac.
How Power Query thinks
- A query connects to a source (a CSV file, a folder, a table, a database, a web page) and lists applied steps that transform the data.
- The steps are written in a language called M, but you rarely need to read it; every button you click adds a step.
- The original source is never changed. The query output is loaded into a new Excel table, a PivotTable, or only into the Data Model.
- Refresh re-runs all steps on the current source data.
Importing a CSV file
- Choose Data › Get & Transform Data › Get Data › From File › From Text/CSV (or the From Text/CSV button).
- Pick the file, for example
sales_march.csv, and click Import. - A preview opens. Check File Origin (encoding, usually UTF-8) and Delimiter (comma or semicolon).
- Click Transform Data (not Load) to open the Power Query Editor.
The editor shows a data preview in the middle, the Applied Steps list on the right (Source, Promoted Headers, Changed Type…), and the ribbon with Home, Transform and Add Column tabs. Each step can be clicked to see the data at that point, renamed, or deleted with the ×.
Cleaning steps
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | order_id | date | customer | region | amount |
| 2 | A-1001 | 03.02.2026 | alpha ltd | north | 1,250.00 |
| 3 | A-1002 | 03.02.2026 | BETA GMBH | South | 860 |
| 4 | |||||
| 5 | A-1003 | 04.02.2026 | gamma sa | north | 2,450.50 |
| 6 | Total | 4,560.50 |
A typical raw export: dates as text, inconsistent case and spaces, a blank row and a total row.
- Remove the blank and total rows: Home › Reduce Rows › Remove Rows › Remove Blank Rows, then filter
order_idwith the drop-down to untickTotal(or use Remove Bottom Rows › 1). - Clean the text: select
customerandregion, then Transform › Text Column › Format › Trim and Format › Capitalize Each Word. - Fix the types: click the type icon in the header of
dateand choose Using Locale… › Date › English (United Kingdom), because the file uses day/month order. Setamountto Decimal Number (with locale English (United States) if it uses commas for thousands). - Rename columns: double-click a header and type
Order,Date,Customer,Region,Amount. - Add a calculated column: Add Column › Custom Column, name
VAT, formula[Amount] * 0.24. - Choose Home › Close & Load. The clean table appears on a new sheet.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Order | Date | Customer | Region | Amount | VAT |
| 2 | A-1001 | 2026-02-03 | Alpha Ltd | North | 1250 | 300 |
| 3 | A-1002 | 2026-02-03 | Beta Gmbh | South | 860 | 206.4 |
| 4 | A-1003 | 2026-02-04 | Gamma Sa | North | 2450.5 | 588.12 |
The loaded result. Note that Capitalize Each Word gave 'Gmbh' and 'Sa'; fix such cases with Replace Values if they matter.
Refresh: the whole point
Next month, save the new export over the old sales_march.csv path (or change the source in Home › Data Source Settings). Then choose Data › Queries & Connections › Refresh All (Ctrl+Alt+F5). All your steps run again on the new file. To refresh one query, right-click it in the Queries & Connections pane and choose Refresh.
Combining data: Append
Append stacks queries on top of each other, for example January, February and March sales with the same columns.
- Create a query for each month (or see the folder method below).
- In the editor choose Home › Combine › Append Queries › Append Queries as New.
- Choose Three or more tables and add the queries in order. Click OK.
- Columns are matched by name. A column that exists in only one source is filled with
nullin the others.
Import a whole folder
Even better: put every monthly file in one folder and choose Data › Get Data › From File › From Folder. Click Combine & Transform, pick a sample file, and Power Query builds a query that appends every file in the folder. Next month, just drop the new file in the folder and refresh. This is the single biggest time saver Power Query offers.
Combining data: Merge
Merge joins two queries side by side on a matching column, like a lookup but for whole tables. Example: add the customer's country from a Customers table to each order.
- Load both tables as queries (from Excel tables: click inside a table and choose Data › From Table/Range).
- In the Orders query choose Home › Combine › Merge Queries.
- Select the
Customercolumn in Orders, choose the Customers query below and select itsCustomercolumn. - Join Kind: Left Outer (all orders, matching customers). The dialog shows how many rows matched; aim for all of them.
- Click OK. A new column with tables appears. Click the expand icon in its header, tick
Country, untick Use original column name as prefix, and click OK.
| Join kind | Keeps |
|---|---|
| Left Outer | All rows from the first table, matches from the second |
| Inner | Only rows that match in both |
| Left Anti | Rows in the first table with no match (great for finding missing customers) |
| Full Outer | Everything from both tables |
Other useful transformations
- Transform › Unpivot Columns: turns a cross-tab with one column per month into a tidy list with Month and Value columns, ideal for PivotTables.
- Home › Group By: totals by category, like a PivotTable inside the query.
- Transform › Split Column › By Delimiter: the robust version of Text to Columns.
- Add Column › Column From Examples: type what you want and Power Query writes the step, like Flash Fill but repeatable.
- Home › Remove Rows › Remove Duplicates on selected columns.
Load options
Home › Close & Load To offers: Table (on a worksheet), PivotTable Report, PivotChart, or Only Create Connection. Tick Add this data to the Data Model to use it with Power Pivot relationships and DAX measures (Power Pivot and the Data Model: relationships and DAX measures). Staging queries used only for merging can be set to Only Create Connection, so they do not clutter the workbook.
A look at M
let
Source = Csv.Document(File.Contents("C:\Data\sales_march.csv"), [Delimiter=",", Encoding=65001]),
Headers = Table.PromoteHeaders(Source),
Trimmed = Table.TransformColumns(Headers, {{"customer", Text.Trim}}),
Typed = Table.TransformColumnTypes(Trimmed, {{"amount", type number}}, "en-US")
in
TypedCheck yourself
1. What happens to the original CSV file when you apply steps in Power Query?
Power Query reads the source and outputs the transformed result elsewhere.
2. Which operation stacks January, February and March files with the same columns?
Append adds rows; Merge adds columns based on a matching key.
3. Which join kind lists orders whose customer is missing from the Customers table?
Left Anti keeps rows from the first table that have no match.
4. Dates like 03.02.2026 mean 3 February. How should you set the type?
Using Locale tells Power Query the day/month order of the source.
5. How do you update the output after a new file has been saved in the source folder?
Refresh re-runs every step against the current source.