Power Query Data Cleaning Techniques
Messy data is what Power Query was built for. This guide covers the cleaning tasks you'll do on almost every dataset — junk headers, mixed types, blank rows, split/merge columns, unpivoting, and error handling — with the ribbon paths and M equivalents.
The cleaning checklist
Work through these in order for most messy imports:
- Remove junk header rows
- Promote real headers
- Remove blank rows and blank columns
- Set data types explicitly
- Trim and clean text
- Split or merge columns as needed
- Handle errors and nulls
- Standardize inconsistent values
- Unpivot wide data if needed
Remove junk header rows
Reports often have title rows, blank lines, and metadata before the actual data.
M equivalent: Table.Skip(Source, 3)
Also useful:
- Remove Bottom Rows — for reports with summary/footer rows
- Remove Alternate Rows — for double-spaced exports
- Remove Duplicates — Home → Remove Rows → Remove Duplicates
- Remove Blank Rows — Home → Remove Rows → Remove Blank Rows
Promote first row to headers
M: Table.PromoteHeaders(Source, [PromoteAllScalars=true])
Remove blank columns
Wide exports often include empty columns. Select them → right-click → Remove.
To find empty columns quickly: filter each column for blanks; if the count equals total rows, remove.
Set data types
The single most important cleaning step. Auto-detected types are guesses.
Or click the icon left of the column name for a quick change.
Common conversions:
- Whole Number — for counts, IDs
- Decimal Number — for currency, measurements
- Date — for date-only values (no time)
- Date/Time — for timestamps
- Text — force numbers to stay as text (useful for IDs like "007")
Dates like "6/9/2026" mean different things in US (June 9) vs UK (September 6). Use Transform → Data Type → Using Locale to specify the source locale explicitly.
Trim and clean text
Trim removes leading and trailing whitespace. Clean removes non-printable characters (line breaks, tabs).
M functions: Text.Trim, Text.Clean, Text.Upper, Text.Lower, Text.Proper
Split columns
By delimiter
Pick the delimiter (comma, space, custom), and choose how to split (at each delimiter, leftmost only, rightmost only).
By number of characters
For fixed-width fields like "USA-042" (country code, then dash, then number). Split at position 3.
By position
Enter multiple positions to split into multiple columns at once.
Merge columns
Pick a separator (space, comma, custom). The columns collapse into one.
Replace values
Simple find-and-replace within a column. Great for fixing inconsistent labels ("USA" and "United States" → both to "US").
Handle nulls
Fill down
When a group column only has values on the first row of each group (common in exports from PivotTables):
Empty cells fill with the value above them.
Replace nulls with a default
Right-click → Replace Values → find null, replace with 0 (or blank text, or whatever).
Standardize inconsistent values
Column from Examples
The friendliest cleaning tool. Give Power Query examples of what you want; it figures out the transformation.
Type the desired result for a few rows. Power Query proposes an M expression. Confirm.
Conditional column
For rule-based categorization:
Fill in rules: "if Amount > 1000 then 'Large' else if Amount > 100 then 'Medium' else 'Small'".
Unpivot columns
The critical reshaping step. Wide data (Q1, Q2, Q3, Q4 columns) into tall data (Quarter, Amount).
Better: select the columns you want to keep as identifiers → Transform → Unpivot Other Columns. This is more resilient to new columns appearing in the source.
Handle errors
When a step fails on some rows (e.g., a text row where a number was expected), those cells show "Error". Options:
Or: right-click column → Remove Errors, which removes rows containing errors in that column.
The full cleaning example
Given a sales report with junk headers, mixed types, wide quarter columns, and blank rows:
Every step is visible, editable, and re-runs on refresh.
Common pitfalls
Setting types before renaming columns means M references old column names in the type step. Rename first, then type.
Filling down assumes rows are ordered correctly. If the query is sorted differently, wrong values fill. Verify sort order before filling.
The preview in the editor is a sample (200 rows by default). Once loaded, edge cases might fail. Review the loaded table before assuming the query is done.