LX

Power Query Data Cleaning in Excel: A Practical Guide

By the LogicExcel Editorial Team••16 min read•3,080 words

Power Query Data Cleaning in Excel: A Practical Guide

Analyst cleaning data in Power Query

Power Query cleans data in Excel by recording each fix as a step, so you build the cleanup once and rerun it on every new export. You load the messy table, set data types, trim text, deal with errors, split combined columns, merge in lookup tables, and click Refresh next month. This guide walks through each of those moves in the order you should do them, with the traps that cost people an afternoon.

TL;DR

  • Power Query records every cleaning action as an Applied Step. Your source data is never altered, and you can edit or delete a step later.
  • Work in a sensible order: profile the data, remove junk rows, fix types, trim and standardize text, handle errors, split columns, then merge.
  • Errors live at the cell level. You can remove the rows, replace the values, or keep them to audit the source.
  • Split by delimiter for "Last, First" style columns, and merge queries instead of copying VLOOKUP formulas down thousands of rows.
  • The skill is muscle memory. Practice the formulas that still matter alongside Power Query, since many cleanups mix both.

Table of Contents

Why clean data in Power Query instead of by hand

Every analyst has done the manual version: delete the first six rows of a report, retype a header, run Find and Replace, paste values, and repeat the whole routine when the next export arrives. It works once. The second time, you forget a step, and the third time, someone changes the file layout.

Power Query (called Get & Transform on the Data tab) fixes that by storing the process rather than the result. According to Microsoft's best practices guidance, the steps you take are recorded in the Query Settings pane as Applied Steps. That has two practical consequences:

  • Non-destructive cleaning. The original file or table stays untouched. If you make a bad call, click the step and fix it or delete it.
  • Repeatability. Paste next month's export over the old data, click Refresh, and the same twenty steps run again.
One caution from the same guidance: step order matters. A later step can break or behave differently if you change or delete an earlier one. Treat the Applied Steps list like a recipe, not a pile of independent actions.

Start by profiling the data

Before you change anything, look. In the Power Query Editor, open the View tab and switch on the profiling tools. Microsoft lists three: Column Quality, Column Distribution and Column Profile. Per Microsoft, Column Quality shows the share of valid, error and empty values, Column Distribution visualizes how often values repeat, and Column Profile gives detailed statistics for the selected column.

Here is what to look for:

  • Empty percentage. A column that is 40 percent empty may be a subtotal layout, not missing data.
  • Error percentage. Anything above zero deserves a look before you decide what to do with it.
  • Distinct versus unique counts. A Customer column with 12 distinct values in 4,000 rows is fine. A State column with 80 distinct values is not; you have "CA", "Calif." and "California" in the same field.
Microsoft's advice is to keep these tools enabled during development so that inconsistencies surface before they spread into later steps. By default the profile samples only the first rows, so switch the status bar option to profile the entire dataset when accuracy matters.

A cleaning sequence that holds up

There is no single correct order, but this one avoids most rework.

1. Remove the junk at the top and bottom

Reports exported from accounting or ERP systems often carry titles, dates and blank lines above the real headers. Use Remove Rows > Remove Top Rows, then Use First Row as Headers. These are among the most common cleaning operations, and they are the ones that make later steps stable. Do the same at the bottom for grand-total rows you do not want in a PivotTable.

2. Filter early

If you only need 2026 transactions, filter now. Microsoft recommends filtering data as early as possible so later transformations process fewer rows. For database sources that support query folding, the filter can be pushed back to the source. For CSV and Excel files, folding does not apply, but a smaller table still means faster refreshes and fewer places for errors to appear.

3. Set data types deliberately

Power Query guesses types when it first loads a table. Check the guesses. Dates that arrive as text, ZIP codes that lost their leading zeros, and IDs read as numbers are classic problems. For ZIP codes and account numbers, set the type to Text. For dates from a different regional format, use Change Type > Using Locale so "03/04/2026" is read the way the source system meant it.

4. Trim and standardize text

Text columns collect invisible damage: trailing spaces, double spaces, mixed case, non-printing characters. Select the columns, then Transform > Format:

  • Trim removes leading and trailing spaces.
  • Clean removes non-printing characters.
  • Capitalize Each Word, UPPERCASE or lowercase standardize case.
The worksheet equivalent is the TRIM function, and it is worth understanding both. Our page on the Excel TRIM function explains what it removes and what it leaves behind, and you can try it in the TRIM practice exercise. Doing the same job in Power Query means you never have to write a helper column.

5. Replace and fix values

Use Replace Values for known substitutions, such as turning "N/A" into null, or "Calif." into "California". Fill Down handles the grouped-report layout where a region name appears once and the blanks below belong to it.

6. Remove duplicates last, not first

Deduplicate after trimming and case standardization. Otherwise "Acme Corp" and "Acme Corp " count as two customers, and you keep both. Remember that Remove Duplicates compares the selected columns only, and it is case-sensitive, which is one more reason to standardize text first.

Removing errors in Power Query

An error in Power Query is not the same as an error in a worksheet. It shows up in a single cell, and the rest of the row is fine. Microsoft's error-handling documentation describes three ways to treat them: remove the rows that contain errors, replace the errors with a fixed value, or keep the rows so the errors serve as an audit trail.

To see why a cell failed, click the white space inside the cell. A pane under the data preview shows the details. That one habit saves a lot of guessing.

Which option to choose

SituationBest moveWhy
Errors in a column you do not useRemove the column, not the rowsYou keep every record
A few bad rows in a large export, and totals must reconcileKeep errors, then investigateRemoving them silently changes totals
Missing values should read as zeroReplace Errors with 0Downstream sums stay clean
Different fallback depending on contextUse a try ... otherwise expressionConditional handling per column
The try expression is the advanced option Microsoft documents: it evaluates a column and returns your otherwise value if an error appears. You can write it in a custom column without being a programmer. Something like try Number.From([Amount]) otherwise 0 turns text that cannot become a number into a zero.

The error you will meet most

The documentation also covers the "column of the table wasn't found" error. It happens when a step refers to a column name that no longer exists, for example because the source file changed a header from "Amount" to "Amt". The fix is to find the step that references the old name and update it, or to build your cleanup so it does not depend on fragile names. Position-based steps and promoted headers help, but there is no magic here. If the source layout changes, a human has to look.

Splitting columns in Power Query

Combined fields are everywhere: "Smith, Jane", "Austin, TX 78701", "SKU-1042-RED". Select the column and choose Split Column on the Home or Transform tab.

Microsoft's documentation says you can split text by delimiter, by number of characters, by position, or by case change such as lowercase to uppercase. Delimiters include colon, comma, equals sign, semicolon, space and tab, and you choose whether to split at the left-most delimiter, the right-most, or at each occurrence.

The choice among those three matters more than people expect:

  • Left-most works for "Smith, Jane" when only the first comma matters.
  • Right-most is the right call for a file path or a product code where the last segment is the one you want.
  • Each occurrence gives you the most columns, so use it when the count is predictable.
For addresses such as "Austin, TX 78701", split at the comma first, then split the second part by space. Two splits are cleaner than one clever one, and each shows up as its own step you can inspect.

If you prefer worksheet formulas, the same logic exists in LEFT, MID and RIGHT. Our guide to Excel text functions shows how they work, and it helps to know both approaches, because Power Query is not always the right tool for a quick one-off fix.

Merging queries in Excel

Merging is where Power Query replaces the VLOOKUP-and-drag routine. Microsoft describes a merge as creating a new query from two existing ones, with a column in the primary table that holds a link to the related table. You then expand that column and choose which fields to bring in.

The steps are short:

  • Load both tables as queries (Data > From Table/Range).
  • In the Power Query Editor, choose Home > Merge Queries.
  • Click the matching column in each table. Matching columns must hold the same data type, which is why you set types first.
  • Pick a join kind.
  • Click the expand icon on the new column and select the fields you need.
For join kinds, think about what you want to keep:
Join kindKeepsTypical use
Left OuterEvery row of the first table, matches from the secondAdd product names to a sales list
InnerOnly rows that match in bothOrders that have a valid customer
Left AntiRows in the first table with no matchFind orders whose customer is missing from the master list
Full OuterEverything from bothReconcile two lists
Left Anti is the underused one. It is a data cleaning tool as much as a combining tool: it hands you the exact records that fail to match, which is usually your dirty data.

If matches fail unexpectedly, the cause is almost always hidden spaces or case differences. Go back and trim the key columns in both queries, then merge again.

Cleaning many files at once

The bigger payoff comes when you point Power Query at a folder. Microsoft's file-combining documentation explains that Combine Files creates a Transform Sample File query. Whatever cleaning you apply to that sample runs on every file in the folder before they are stacked together.

That is how a monthly routine becomes a one-click job: drop 12 CSV exports in a folder, clean the sample once, and refresh. The approach can be brittle if file structures change, so keep a consistent header row and check Column Quality after each refresh.

Folder files cleaned from one sample and combined

Performance and privacy: two settings to understand

Two concepts trip up people who move from small files to larger sources.

Query folding. Per Microsoft, folding translates your Power Query steps into native queries the data source runs. Steps that cannot fold run inside the Power Query engine, which is slower on large data. Many common sources, including CSV and Excel files, do not support folding, so for those the advice is to filter early and keep the step list lean. Privacy levels. When you combine data from several sources, Power Query may ask you to set each as Private, Organizational or Public. Microsoft's privacy levels page explains that restrictive isolation blocks data from moving between sources, which can reduce performance. It is tempting to switch on the setting that ignores privacy levels. Microsoft's security guidance recommends configuring levels for each data source instead. If your workbook mixes a customer list with a public price feed, set the customer file to Private and leave it that way.

Our perspective: practice the logic, then automate it

We build LogicExcel around one belief: people learn Excel by doing, not by watching. That applies to Power Query as much as to formulas. The learners we see struggle with data cleaning are rarely missing a button. They are missing the instinct for what "clean" means: which columns are keys, which values should be text, where a stray space will break a match.

That instinct comes from formulas first. If you have trimmed a column with TRIM, split a code with LEFT and MID, and watched a lookup fail on a hidden space, then you know exactly what to do in the Power Query ribbon, and you can read the M code it writes for you. If you jump straight to the ribbon, you click buttons and hope.

Our advice for anyone building this skill:

  • Clean a small, deliberately dirty sample by hand with formulas, so you feel each problem.
  • Then rebuild the same cleanup in Power Query and compare the results.
  • Build the habit of checking Column Quality after each step, not at the end.
  • Keep queries short and named, so a colleague can follow them in six months.
Power Query rewards the person who already knows what they are trying to produce. Practice the thinking, and the tool becomes fast.

> — Thomas Houza

Build the underlying skills for free

Power Query sits on top of ideas you can drill without installing anything. On LogicExcel you can work through 95 free Excel exercises in a real spreadsheet-like environment, get instant feedback, and see an explanation of every mistake. There is no account and no payment. If you want a short route into the topic, the Power Query lesson in Five Wins shows how to clean a table once and reuse it. For sample data to practice on, see our free practice datasets.

Common mistakes and quick fixes

  • Changing types before removing junk rows. Headers become data, types guess wrong, and later steps fail. Promote headers first.
  • Hard-coded column names in custom steps. They break when the source renames a field. Check Applied Steps after any source change.
  • Deleting error rows without looking. You may be deleting real transactions. Click into the error cell and read the message first.
  • Forgetting to refresh. Query results do not update until you refresh. Make it part of your monthly checklist.
  • Loading everything to a worksheet. If you only need a PivotTable, load the query as a connection and a data model, and keep the sheet light. Our PivotTables lesson picks up from there.
  • Leaving diagnostics on. Query diagnostics are useful for troubleshooting slow steps, but the logs can contain data values and paths, so switch them off when you are done.

Where to go next

Once the basics feel natural, two directions pay off. One is automation: our piece on using Excel to automate data analysis tasks shows how cleaning fits into a wider reporting routine. The other is finance work, where messy exports are the norm. The Excel for Accounting course covers month-end reporting, and 5 Days to Better Accounting Spreadsheets is a short free start.

FAQ

How do I remove errors in Power Query?

Select the column, then use Remove Rows > Remove Errors to drop the rows, or Replace Errors to put a fixed value in their place. Click inside an error cell first to read the details in the pane under the preview. Microsoft's guidance also lets you keep errors as an audit tool.

How do I split a column in Power Query?

Select the column and choose Split Column on the Home or Transform tab, then pick By Delimiter, By Number of Characters or By Positions. For delimiters you can split at the left-most, right-most or each occurrence. Check the result in Applied Steps and change the data types of the new columns.

How do I merge queries in Excel?

Load both tables as queries, open the Power Query Editor, and choose Merge Queries on the Home tab. Select the matching column in each table, pick a join kind such as Left Outer, then expand the new column to bring in the fields you want. Trim and type-match both key columns first.

Does Power Query change my original data?

No. Your source stays as it was, and Power Query records the cleaning as Applied Steps that run on refresh. You can edit or delete any step later. Results appear in a new table or connection, not over your original range.

Sources

Recommended

Keep going

Guides people read next.