Power BI Data Cleaning Guide
Cleaning Messy Sales Data in Power BI
A practical, step-by-step walkthrough for the messy_sales_data.csv practice file
This guide takes the raw messy_sales_data.csv file and walks you through every transformation
needed in Power Query to turn it into a clean, report-ready table. Each step lists the exact
problem in the data, where to click, and what to type. Work top to bottom; the order matters
because some steps are easier once earlier ones are done.
The mess you are fixing
Before touching anything, here is what is wrong with the 13 columns. Keep this as your
checklist.
Column
Problem
Target state
OrderDate
Seven mixed formats (US, EU, ISO, dotted,
text)
Single Date type
CustomerName
Random casing and trailing spaces
Trimmed, proper case
Email
Padded, wrong case, malformed (at)
Trimmed lowercase text
Country
USA vs U.S.A. vs United States vs us
One value per country
Region
Casing and the typo centrral
Clean category
Product
Casing and double spaces
One value per product
Category
Casing, stationary typo, nulls
Clean category
Quantity
Negatives, outliers, missing
Whole number, validated
UnitPrice
$, USD, comma decimals, padding
Decimal number
Discount
5%, 20 percent, 0,15 mixed
Decimal 0 to 1
Returned
Yes, Y, TRUE, 1 mixed
True/False
Phone
Many formats, missing
Standard text
All
Blank rows, junk row, duplicates
Removed
Part 1: Load and inspect
Step 1. Import the file
1. Open Power BI Desktop and choose Home > Get data > Text/CSV.
2. Select messy_sales_data.csv and click Open.
3. In the preview window, do NOT click Load. Click Transform Data to open Power Query
Editor. All cleaning happens here.
Why: Loading first bakes in the wrong data types. Transforming first lets you fix everything
before it reaches the model.
Step 2. Turn on the data profiler
4. In Power Query, go to the View tab.
5. Tick Column quality, Column distribution, and Column profile.
Page 1
Power BI Data Cleaning Guide
6. Click the dropdown under the profiler and set it to profile the entire data set, not just the
top 1000 rows.
Why: These give you the percent of valid, error, and empty values per column so you can see
the mess and confirm each fix worked.
Part 2: Remove the obvious junk
Step 3. Promote headers and check column count
If the first row is not already the header, use Home > Use First Row as Headers. Confirm you
have 13 columns: OrderID through Phone.
Step 4. Remove blank and junk rows
7. Go to Home > Remove Rows > Remove Blank Rows to drop the fully empty row.
8. Find the junk row where OrderID is ORD-XXXX (it has not a date, bad@@email, junk
values). Click the OrderID filter dropdown and untick that value, or filter Quantity to remove
the text abc.
Tip: Do this early. Junk rows distort the profiler percentages and can break type conversions
later.
Part 3: Clean the text columns
Step 5. Trim and clean every text column
Whitespace and hidden characters hide in CustomerName, Email, Country, Region, Product,
Category, and Phone.
9. Select all text columns (Ctrl click each header).
10. Go to Transform > Format > Trim, then Transform > Format > Clean.
Trim removes leading and trailing spaces. Clean removes non printable characters. Note that
Trim does not collapse double spaces inside text, which is handled in Step 8.
Step 6. Fix casing on names
11. Select CustomerName.
12. Go to Transform > Format > Capitalize Each Word. This turns MICHAEL and john into
Michael and John.
13. Select Email, then Transform > Format > lowercase so addresses are consistent.
Part 4: The hardest column, OrderDate
OrderDate mixes formats like 11/7/2023, 26.11.2022, 27-11-2022, 2024-12-13, and Dec 27,
2024. A single Change Type to Date will throw errors on most of them. Use one of the two
approaches below.
Step 7a. Recommended: split by format with a conditional column
The cleanest path is to standardize the text first, then convert. A quick reliable method:
14. Right click OrderDate and Change Type > Text so nothing auto converts yet.
Page 2
Power BI Data Cleaning Guide
15. Add a custom column that normalizes separators and reorders parts. Use Add Column >
Custom Column with logic that replaces dots and dashes with slashes, then parses. A
compact version:
= try Date.FromText([OrderDate], [Format="M/d/yyyy", Culture="en-US"])
otherwise try Date.FromText([OrderDate], [Format="d-M-yyyy", Culture="en-GB"])
otherwise try Date.FromText([OrderDate], [Format="yyyy-M-d"])
otherwise try Date.FromText([OrderDate], [Format="yyyy/M/d"])
otherwise try Date.FromText([OrderDate], [Format="d.M.yyyy"])
otherwise try Date.FromText([OrderDate]) otherwise null
16. Name the column CleanDate, set its type to Date, then remove the original OrderDate
column and rename CleanDate to OrderDate.
Why the try/otherwise chain: It attempts each known format in turn and falls back to null
instead of erroring, so one bad value never stops the whole column.
Step 7b. Simple alternative: Locale conversion
If most of your rows share one regional style, you can try Transform > Data Type > Using
Locale and pick English (United States) or English (United Kingdom). This is faster but will leave
the formats it cannot match as errors, which you then handle in Step 15.
Part 5: Standardize categories
Step 8. Collapse Product variants
17. Select Product, then Transform > Format > Capitalize Each Word.
18. Use Transform > Replace Values to collapse double spaces. Replace two spaces with
one space.
After that, Wireless Mouse, wireless mouse, and Wireless Mouse all become Wireless Mouse.
Repeat Replace Values for any remaining near duplicates such as Monitor 27inch to Monitor
27" if you want them unified.
Step 9. Standardize Country
Right click Country > Replace Values and map every variant to one canonical name. Do each
row below.
Replace these
With
U.S.A., us, United States of America, United States
USA
U.K., United Kingdom, England
UK
germany, DE, Deutschland
Germany
CA, canada
Canada
AUS, australia
Australia
FR, france
France
Faster option: Right click Country > Group, or use a small merge against a lookup table if you
prefer not to hand map. For practice, Replace Values is clearest.
Step 10. Standardize Region and Category
19. On Region, apply Capitalize Each Word, then Replace Values to fix centrral to Central.
Page 3
Power BI Data Cleaning Guide
20. On Category, apply Capitalize Each Word, fix Stationary to Stationery, and leave nulls for
Step 15.
Part 6: Fix the numeric columns
Step 11. Convert UnitPrice to a real number
UnitPrice holds values like $618.32, 866.40 USD, 531,07 and padded text. Strip the noise
before converting.
21. Select UnitPrice. Use Replace Values to remove the dollar sign: replace $ with nothing.
22. Replace USD with nothing, then Trim again to drop spaces.
23. Handle comma decimals: replace , with . so 531,07 becomes 531.07. (Only safe here
because there are no thousands separators in this file.)
24. Right click UnitPrice > Change Type > Decimal Number. Any leftover non numeric
values become errors you will catch in Step 15.
Step 12. Validate Quantity
25. Right click Quantity > Change Type > Whole Number. The values N/A and dash become
errors; that is expected.
26. Filter out impossible values: click the Quantity filter and use Number Filters to remove
anything less than 1 (this drops the negatives).
27. Decide on outliers like 9657. For practice, add a filter for values greater than 200 to review
them, then either keep or cap them. Document your choice.
Step 13. Standardize Discount
Discount mixes 0.05, 5%, 20 percent, and 0,15. Goal: a decimal between 0 and 1.
28. Replace percent with %, then replace the % sign with nothing, and replace comma with
period.
29. Add a conditional or custom column: if the original text contained a percent sign, divide the
number by 100. A simple route is to standardize everything to the same scale, then
Change Type to Decimal Number.
Sanity check: 5% and 0.05 should both end up as 0.05. Use the column distribution to confirm
values sit between 0 and 1.
Part 7: Booleans and contact fields
Step 14. Convert Returned to True/False
30. Select Returned. Use Replace Values repeatedly to map: Yes, Y, TRUE, 1 to true; and
No, N, FALSE, 0 to false.
31. Right click Returned > Change Type > True/False. Leave blanks and N/A as null for Step
15.
Step 15. Tidy Email and Phone
• Email: already trimmed and lowercased. For practice, add a column flagging invalid
addresses, for example rows where the text does not contain an @ symbol, so you can
report data quality.
Page 4
Power BI Data Cleaning Guide
• Phone: this is reference text, not a number. Keep it as text. Optionally use Replace Values
to strip dots, parentheses, and spaces if you want a single digit only format. Never set
Phone to a number type, since leading characters and length would break.
Part 8: Nulls, errors, and duplicates
Step 16. Standardize missing values
Missing data appears as blank, N/A, null, NULL, dash, #N/A, and unknown. Make them all real
nulls so the report treats them consistently.
32. Select the affected columns. Use Replace Values with Advanced options to replace
each token (N/A, null, -, unknown) with nothing, which Power Query reads as null for typed
columns.
33. Go to Home > Remove Errors on the columns where you converted types (OrderDate,
Quantity, UnitPrice) to clear values that could not convert.
34. Decide a policy per column: replace nulls with a default (for example Region = Unknown)
using Replace Values > replace null, or keep them as null. Be deliberate and note it.
Step 17. Remove duplicate rows
35. The file has roughly 15 duplicate and near duplicate rows. First make sure casing is
already normalized (done in earlier steps), so near duplicates now match exactly.
36. Select all columns, then Home > Remove Rows > Remove Duplicates.
Careful: If two legitimately different orders share an OrderID by coincidence, removing
duplicates on OrderID alone would delete real data. Removing duplicates across all columns is
safer for this dataset.
Part 9: Finalize and model
Step 18. Set final data types and add a revenue column
37. Confirm each column type: OrderID text, OrderDate date, Quantity whole number,
UnitPrice and Discount decimal, Returned true/false, the rest text.
38. Add a calculated column for net revenue using Add Column > Custom Column:
= [Quantity] * [UnitPrice] * (1 - [Discount])
39. Rename the query to something clean like Sales, then click Home > Close & Apply to
load it into the model.
Step 19. Build the report
With clean data loaded, create a few starter visuals on the report canvas:
• A Card showing total revenue. Create a measure: Total Revenue = SUMX(Sales,
Sales[Quantity] * Sales[UnitPrice] * (1 - Sales[Discount])).
• A Line chart of revenue by OrderDate, set the axis to a proper date hierarchy.
• A Bar chart of revenue by Country, now that countries are consolidated.
• A Donut or Bar of revenue by Category or Product.
• A Card or KPI for return rate: divide returned orders by total orders.
Page 5
Power BI Data Cleaning Guide
Add slicers for Country, Category, and OrderDate so the report is interactive. Because the data
is clean, your axes and legends will no longer show duplicate spellings.
Quick reference: problem to action
Problem in data
Power Query action
Trailing or hidden spaces
Transform > Format > Trim and Clean
Mixed casing
Format > Capitalize Each Word or lowercase
Mixed date formats
try/otherwise Date.FromText chain or Locale convert
Inconsistent categories
Replace Values mapping to one canonical value
Numbers stored as text
Strip symbols with Replace Values, then Change Type
Comma decimals
Replace comma with period, then Change Type
Mixed booleans
Replace Values to true/false, then Change Type
Many null tokens
Replace Values (advanced) to null
Conversion failures
Home > Remove Errors
Duplicate rows
Remove Duplicates across all columns
Impossible values
Number Filters to exclude or cap
Keep every step visible in the Applied Steps pane on the right. That pane is your audit trail; you
can click any step to see the data at that point, rename steps for clarity, and reorder or delete
them if you make a mistake.
Page 6