Clean a Messy Sales Dataset in Power Query
Part of the Power BI Roadmap
In short
This project pulls together everything in this phase. You start with a file that looks like a real export from a small distributor, full of junk, and end with a clean table you would happily show a manager.
A project taking a deliberately messy sales file with bad headers, mixed date formats, duplicates and wide month columns, and turning it into a clean, analysis-ready table.

Think of it like this
Restoring an old cycle
You find a rusty cycle in the store room. You don't paint it first. You remove the junk tied to it, straighten the wheel, oil the chain, replace the brakes and only then polish it. Cleaning a dataset follows the same order: remove junk, fix structure, fix values, then polish.
Watch it happen
The cleaning order that works
1/6Skip three title rows and filter out the Grand Total line.
The big ideas
What you need to know
Structure before values
Fix rows, headers and shape first. Types and text cleanup come after, so they apply to the final columns.
Rename steps
Rename Applied Steps like 'Removed title rows' so anyone can read the recipe later.
Reconcile totals
Compare the total units in Power BI with the total in the original file. They should match exactly.
Document assumptions
Write down choices like 'N/A units treated as null' in the step names or a notes page.
See it in code
Walk through the code
1let2 Source = Excel.Workbook(File.Contents("D:\Data\distributor_export.xlsx"), null, false),3 Raw = Source{[Item = "Sales", Kind = "Sheet"]}[Data],4 #"Removed title rows" = Table.Skip(Raw, 3),5 #"Promoted headers" = Table.PromoteHeaders(#"Removed title rows", [PromoteAllScalars = true]),6 #"Clean header names" = Table.TransformColumnNames(#"Promoted headers", Text.Trim),7 #"Renamed" = Table.RenameColumns(#"Clean header names", {{"Cust City", "City"}}),8 #"Removed total" = Table.SelectRows(#"Renamed", each [Product] <> null and [Product] <> "Grand Total"),9 #"Trimmed text" = Table.TransformColumns(#"Removed total", {{"City", Text.Proper}, {"Product", Text.Trim}}),10 #"Unpivoted months" = Table.UnpivotOtherColumns(#"Trimmed text", {"Product", "City"}, "Month", "Units"),11 #"Typed" = Table.TransformColumnTypes(#"Unpivoted months", {{"Units", Int64.Type}}, "en-IN"),12 #"Errors to null" = Table.ReplaceErrorValues(#"Typed", {{"Units", null}}),13 #"Removed duplicates" = Table.Distinct(#"Errors to null")14in15 #"Removed duplicates"1/4Fix the structure: skip title rows, promote headers, trim stray spaces from header names and rename.
The full cleaning recipe with readable step names. Each step does one job, in an order that keeps later steps simple.
Save yourself the pain
Common mistakes
Oops
Changing types before unpivoting, then again after.
Do this instead
Shape first, then set types once at the end. Fewer type steps means fewer refresh errors.
Oops
Declaring the dataset clean without checking totals.
Do this instead
Reconcile: total Units in Power BI must equal the total in the source file, minus anything you removed on purpose.
Your mission
Clean the distributor file
Quick check
Why trim and fix header names before renaming or unpivoting?
Go deeper
- 1Find a messy dataset on Kaggle or create one from a clean file.
- 2Keep every step named and documented.
- 3Write a short before-and-after note listing each problem and fix.
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.