Power Query in Excel: Get and Transform Data, Step by Step

8 min read

Power Query is Excel’s built-in tool for importing and cleaning data, found under Data > Get Data (the Get and Transform Data group). You connect to a file, folder, table or database, clean the data in the Power Query Editor, and load the result to a sheet or the data model. Every cleaning step is recorded, so next month you press Refresh and the same steps run again on the new data.

That is the point: cleaning a monthly export by hand takes an hour every month, and in Power Query it takes an hour once. It is built into Excel 2016 and later on Windows and Microsoft 365 on a Mac.

The data used throughout

A tea distributor in Kolkata has three branch offices, at Kolkata, Siliguri and Guwahati. Each month every branch emails a CSV of packs sold per product, one column per week, and head office used to combine, fix and price them by hand. Here is the Siliguri file for October 2026.

SKU Product W1 W2 W3 W4
T101 assam ctc 1kg (with stray spaces) 120 135 110 140
T205 Darjeeling Leaf 250g 40 38 52 45
T310 Green Tea 100g 25 30 28 22

And the price list head office keeps in the workbook, as an Excel Table called tblPrices.

SKU Price per pack
T101 410
T205 360
T310 185

The target is one long table, one row per branch, product and week, with a value column, that a pivot table or a dashboard can read and that rebuilds itself when November’s files arrive.

Where Power Query lives in Excel

These are the menu paths you will use most, in current Excel for Windows.

Task Menu path
Import a CSV or text file Data > Get Data > From File > From Text/CSV
Import every file in a folder Data > Get Data > From File > From Folder
Import a table or range in this workbook Data > From Table/Range
Open the editor without importing Data > Get Data > Launch Power Query Editor, or Alt+F12
See all queries in the workbook Data > Queries and Connections
Refresh everything Data > Refresh All, or Ctrl+Alt+F5

In Excel 2016 the group is labelled Get and Transform and some items sat under New Query. Excel 2010 and 2013 needed Power Query as a separate add-in, which is no longer updated, so use a current version if you can.

Step 1: combine the three branch files from a folder

Save the three CSVs into one folder, such as Branch sales 2026-10. Then:

  1. Data > Get Data > From File > From Folder, and pick the folder.
  2. Excel lists the files. Click Combine > Combine and Transform Data.
  3. In the Combine Files dialog, pick the first file as the sample and click OK.

The Power Query Editor opens with all three files stacked into one table, and a Source.Name column holding each file’s name, such as Siliguri.csv. That column is how you will know which branch each row came from. Rename it Branch and use Transform > Replace Values to strip “.csv”.

Next month, drop November’s files into the folder and refresh; there are no new import steps.

Step 2: the editor and its Applied Steps

The Power Query Editor has the ribbon across the top, the list of queries on the left, a preview of the data in the middle, and the Applied Steps pane on the right. Every click you make adds a step to that list, written in Power Query’s own formula language, called M. You do not have to write M, but it helps to recognise it in the formula bar (View > Formula Bar).

Select any step to see the data at that point, delete one with the cross beside it, and rename steps (right-click > Rename) so the next person can follow them.

Step 3: clean and reshape

These are the steps for the branch data, in order. The last column shows the M function each one writes, which is what you will see in the formula bar.

Step Where to click What it does here M function written
Use first row as headers Home > Use First Row as Headers Only needed if the headers arrived as Column1, Column2 and so on Table.PromoteHeaders
Trim Select Product, Transform > Format > Trim Removes leading and trailing spaces Table.TransformColumns with Text.Trim
Capitalise Transform > Format > Capitalize Each Word assam ctc 1kg becomes Assam Ctc 1kg Table.TransformColumns with Text.Proper
Unpivot Select SKU, Product and Branch, Transform > Unpivot Columns > Unpivot Other Columns Turns the four week columns into rows Table.UnpivotOtherColumns
Rename Double-click the Attribute and Value headers Attribute becomes Week, Value becomes Packs Table.RenameColumns
Set data types Click the icon at the left of each header Packs to Whole Number, the rest to Text Table.TransformColumnTypes
Remove duplicates Select SKU, Branch and Week, Home > Remove Rows > Remove Duplicates Drops a row if a branch sent the same week twice Table.Distinct

Notice that Capitalize Each Word gives “Assam Ctc 1kg”, not “Assam CTC 1kg”. Power Query applies the rule mechanically, like Excel’s PROPER. If the exact name matters, use Replace Values for that product, or better, take the product name from a master table in the merge step below instead of trusting the branch file.

Unpivot, the step that changes everything

The branch files are wide: one column per week. Pivot tables and charts want data long: one row per fact. Unpivot Other Columns keeps the columns you selected and turns all the others into pairs of attribute and value. For Siliguri’s first product, the result is four rows.

Branch SKU Product Week Packs
Siliguri T101 Assam Ctc 1kg W1 120
Siliguri T101 Assam Ctc 1kg W2 135
Siliguri T101 Assam Ctc 1kg W3 110
Siliguri T101 Assam Ctc 1kg W4 140

Three products times four weeks gives 12 rows for Siliguri. Choosing Unpivot Other Columns rather than Unpivot Columns matters: if a branch adds a W5 column in a five-week month, Other Columns picks it up on refresh, whereas selecting W1 to W4 by name would ignore it.

Step 4: merge in the price list

To get a value for each row, the query needs the price from tblPrices. First bring the price list into Power Query: click inside it on its sheet and choose Data > From Table/Range, then Close and Load To > Only Create Connection. Then, back in the branch query:

  1. Home > Merge Queries.
  2. In the top table select SKU; pick tblPrices underneath and select its SKU.
  3. Join Kind: Left Outer (all from first, matching from second). Click OK.
  4. A new column of tables appears. Click the expand icon in its header, tick only Price per pack, and untick “Use original column name as prefix”.
  5. Add Column > Custom Column, name it Value, formula =[Packs]*[Price per pack].

Merge Queries is a lookup done once for the whole table, and it does the same job as a VLOOKUP or XLOOKUP copied down every row. If you know SQL, it is a join, and the join kinds in the dialog match the ones in our guide to SQL joins: Left Outer is a LEFT JOIN, Inner is an INNER JOIN, and Left Anti returns rows with no match, which is the quickest way to find a SKU missing from the price list.

For Siliguri, the merged and calculated result, grouped by product with Home > Group By (Sum of Packs and Sum of Value), is this.

SKU Product Packs in October Price per pack Value
T101 Assam Ctc 1kg 505 410 207050
T205 Darjeeling Leaf 250g 175 360 63000
T310 Green Tea 100g 105 185 19425
Total 785 289475

Merge adds columns side by side. Home > Append Queries stacks tables of the same shape on top of each other; the folder combine in Step 1 is an append done for you.

Step 5: load to a table or to the data model

Home > Close and Load puts the result on a new sheet as an Excel Table. Close and Load To gives you the choice, and the right one depends on size and use.

Load option What you get Use it when
Table An Excel Table on a sheet You or others need to see and filter the rows; up to Excel’s 1,048,576-row limit
PivotTable Report A pivot table, with no rows on a sheet You only need the summary
PivotChart A pivot chart and its pivot Same, with a chart
Only Create Connection Nothing on a sheet; the query exists for others to use Lookup tables like tblPrices, or a staging query that another query merges
Add this data to the Data Model (tick box) The rows stored in Excel’s compressed model, with relationships and DAX measures through Power Pivot Data beyond the row limit, or several related tables

The data model is the same engine Power BI uses, and it lets one pivot table summarise millions of rows that would never fit on a sheet. It needs Excel for Windows, because Power Pivot is not available in Excel for Mac.

Step 6: refresh

When November’s files are in the folder, Data > Refresh All (Ctrl+Alt+F5) reruns every step and replaces the loaded table. To refresh without being asked, right-click the query in Queries and Connections > Properties and tick one of these.

Setting Effect
Refresh data when opening the file Runs every query on open
Refresh every N minutes Reruns on a timer, useful for a shared file on a network drive
Enable background refresh Lets you keep working while it runs
Refresh this connection on Refresh All Untick for a slow query you only want to run on purpose

If the folder moves, edit the Source step (the cog beside it in Applied Steps) rather than building a new query.

Mistakes that break a query on refresh

Leaving the automatic Changed Type step. Power Query adds a “Changed Type” step on import that names every column. When a branch file arrives with a W5 column, or without W4, that step fails with “column not found”. Delete it and set types yourself after the unpivot, when the column names are stable.

Dates read the wrong way round. A CSV date of 03-10-2026 can be read as 10 March by a machine set to US format. Right-click the column header > Change Type > Using Locale, choose Date and English (India), and it becomes 3 October.

Expecting Remove Duplicates to ignore case. Power Query’s Remove Duplicates is case-sensitive, unlike Excel’s own Data > Remove Duplicates, so “T101” and “t101” are two values. Trim and fix the case first. Our lesson on removing duplicates and cleaning data in Excel, part of this series, compares the two.

Typing into the loaded table. The next refresh replaces it. Put corrections into the query as a step, or into a separate table that the query merges.

A Formula.Firewall error when merging. This comes from privacy levels when a query combines sources of different kinds. For your own files, set them to the same level under Data > Get Data > Query Options > Privacy, or tick “Ignore the Privacy Levels” for that workbook only.

Power Query on a Mac, and in Power BI

On Excel for Mac, Power Query needs Microsoft 365 and is under Data > Get Data. The editor works the same way, but it connects to fewer sources than Windows and there is no Power Pivot, so build data-model work on Windows.

Power BI uses the same Power Query, with the same editor and the same M language, so everything above carries over directly. Our lesson on Power Query in Power BI, coming next in this series, picks up from here, and our Power BI tutorial shows where it fits in a full report.

Frequently asked questions

What is Power Query in Excel?

Power Query is Excel’s tool for importing, cleaning and reshaping data before it reaches a sheet. You find it under Data > Get Data, and every cleaning step you take in its editor is recorded so it can be rerun with a single refresh. It is built into Excel 2016 and later on Windows and into Microsoft 365 for Mac.

How do I open Power Query in Excel?

Go to Data > Get Data and choose a source, which opens the Power Query Editor after a preview. To open the editor without importing anything, use Data > Get Data > Launch Power Query Editor, or press Alt+F12. To edit an existing query, double-click it in the Queries and Connections pane.

What is the difference between Power Query and Power Pivot?

Power Query gets and cleans data; Power Pivot models it. Power Query imports from files, folders and databases, reshapes the data and loads it. Power Pivot works on data loaded to the data model, where you relate tables and write DAX measures for pivot tables. Most data-model workbooks use both, Power Query first.

Is Power Query better than formulas for cleaning data?

For cleaning that repeats, yes. Formulas recalculate on the sheet and need copying down every month, whereas Power Query steps rerun on refresh and handle any number of rows without slowing the sheet. For a one-off fix on a small sheet, a formula such as TRIM or a quick Remove Duplicates is faster.

Do I need to learn the M language?

Not to start. The editor writes M for you as you click, and most everyday cleaning never needs it typed by hand. Reading M in the formula bar becomes useful when you want to change a step slightly, such as a column name or a filter value, without redoing it.

Can Power Query handle more than a million rows?

Yes, if you load the result to the data model instead of a sheet. A sheet stops at 1,048,576 rows, but the data model stores data compressed and can hold many millions of rows on a reasonably specified machine. Choose Close and Load To, Only Create Connection, and tick “Add this data to the Data Model”.

From a tidy query to a working report

Power Query is where analysts stop doing the same work twice. Once the branch data loads clean and long, it feeds pivot tables and a dashboard that refresh in one click, which is the subject of our Excel dashboard lesson in this series. For the formulas that still sit on the sheet, see our guide to Excel for data analysis.

SkilloVilla’s Excel: Beginner to Advanced course has modules on data cleaning techniques and on Power Pivot for working with large data from multiple sources, alongside lookup functions, pivot tables and interactive dashboards, taught in live classes. If you want Excel inside a full analyst programme with SQL, Python, Power BI and placement support, see the Data Analytics with Python track.

How to Build an Excel Dashboard, Step by Step

Build an interactive Excel dashboard step by step: data layout, pivot set-up, KPI formulas with GETPIVOTDATA, chart choices, slicers and refresh.
SkilloVilla Team
8 min read

Data Validation in Excel: Drop-Down Lists and Entry Rules

Data validation in Excel with examples: drop-down lists, dependent drop-downs, date and number limits, custom formula rules and error messages.
SkilloVilla Team
7 min read

Conditional Formatting in Excel, With Formula Rules and Examples

Conditional formatting in Excel explained: highlight rules, top and bottom, data bars, colour scales, icon sets, and formula rules that colour a whole row.
SkilloVilla Team
7 min read

Leave a Reply