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.

Intermediate 20 min read

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

  1. Choose Data › Get & Transform Data › Get Data › From File › From Text/CSV (or the From Text/CSV button).
  2. Pick the file, for example sales_march.csv, and click Import.
  3. A preview opens. Check File Origin (encoding, usually UTF-8) and Delimiter (comma or semicolon).
  4. 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

ABCDE
1order_iddatecustomerregionamount
2A-100103.02.2026 alpha ltd north1,250.00
3A-100203.02.2026BETA GMBHSouth860
4
5A-100304.02.2026gamma sanorth 2,450.50
6Total4,560.50

A typical raw export: dates as text, inconsistent case and spaces, a blank row and a total row.

  1. Remove the blank and total rows: Home › Reduce Rows › Remove Rows › Remove Blank Rows, then filter order_id with the drop-down to untick Total (or use Remove Bottom Rows › 1).
  2. Clean the text: select customer and region, then Transform › Text Column › Format › Trim and Format › Capitalize Each Word.
  3. Fix the types: click the type icon in the header of date and choose Using Locale… › Date › English (United Kingdom), because the file uses day/month order. Set amount to Decimal Number (with locale English (United States) if it uses commas for thousands).
  4. Rename columns: double-click a header and type Order, Date, Customer, Region, Amount.
  5. Add a calculated column: Add Column › Custom Column, name VAT, formula [Amount] * 0.24.
  6. Choose Home › Close & Load. The clean table appears on a new sheet.
ABCDEF
1OrderDateCustomerRegionAmountVAT
2A-10012026-02-03Alpha LtdNorth1250300
3A-10022026-02-03Beta GmbhSouth860206.4
4A-10032026-02-04Gamma SaNorth2450.5588.12

The loaded result. Note that Capitalize Each Word gave 'Gmbh' and 'Sa'; fix such cases with Replace Values if they matter.

Tip. Set data types as one of the last steps you check. A wrong type silently breaks later steps, and Power Query's automatic Changed Type step sometimes guesses wrong (for example reading product codes like 00123 as numbers). Delete or edit that automatic step if needed.

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.

Watch out. Do not type into a table loaded by Power Query: your edits will be overwritten at the next refresh. Make changes in the query, or add extra columns to the right of the table (they stay aligned only if rows keep the same order, so prefer adding the calculation inside the query).

Combining data: Append

Append stacks queries on top of each other, for example January, February and March sales with the same columns.

  1. Create a query for each month (or see the folder method below).
  2. In the editor choose Home › Combine › Append Queries › Append Queries as New.
  3. Choose Three or more tables and add the queries in order. Click OK.
  4. Columns are matched by name. A column that exists in only one source is filled with null in 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.

  1. Load both tables as queries (from Excel tables: click inside a table and choose Data › From Table/Range).
  2. In the Orders query choose Home › Combine › Merge Queries.
  3. Select the Customer column in Orders, choose the Customers query below and select its Customer column.
  4. Join Kind: Left Outer (all orders, matching customers). The dialog shows how many rows matched; aim for all of them.
  5. 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 kindKeeps
Left OuterAll rows from the first table, matches from the second
InnerOnly rows that match in both
Left AntiRows in the first table with no match (great for finding missing customers)
Full OuterEverything 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

Power Query 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
    Typed
Home › Advanced Editor shows the M code behind the steps. Each line is one applied step.
Note. Power Query is in Excel 2016 and later for Windows (Excel 2010 and 2013 needed a free add-in), and in Microsoft 365 for Mac, where most connectors and the editor are now available. Excel for the web can refresh many queries and has a growing editor. File paths are stored in the query, so a workbook moved to another computer may need Data Source Settings › Change Source.

Check yourself

1. What happens to the original CSV file when you apply steps in Power Query?

2. Which operation stacks January, February and March files with the same columns?

3. Which join kind lists orders whose customer is missing from the Customers table?

4. Dates like 03.02.2026 mean 3 February. How should you set the type?

5. How do you update the output after a new file has been saved in the source folder?