Ravindra BagaleCourses & study guides मराठी Track your progress

7. Data Cleaning A–Z in Power Query

Practice and Answer Key: Data Cleaning in Power Query

Suppose we are cleaning a Blinkit Pune export before the March review. Here are five raw rows (fictional practice data). The blank City cell is a real empty cell (it shows null in Power Query).

Order ID City Order Date Amount
␣blk-301 pune␣ 14-03-2025 ₹1,250
BLK-301 Pune 14-03-2025 ₹1,250
BLK-302 PUNE 15-03-2025 ₹980
BLK-303 (null) 15-03-2025 ₹400
BLK-304 Nashik 16-03-2025 ₹2,100

About this data: This table uses columns: Order ID, City, Order Date, Amount. This table uses columns: What you see, Why, Fix. Values shown are the lesson examples already on this page (not a new dataset).

(␣ = an extra space.)

Exercise (one under the other):

  1. Type the rows in Excel, save, and load with Get data › Excel workbook › Transform Data.
  2. Order ID: Transform › Format › Trim, then UPPERCASE.
  3. City: Transform › Format › Trim, then Capitalize Each Word.
  4. City: Transform › Fill › Down.
  5. Amount: Replace Values ₹ → nothing, then , → nothing. Change type to Fixed decimal number.
  6. Order Date: right-click › Change Type › Using Locale… › Date, English (India).
  7. Select Order ID › Home › Remove Rows › Remove Duplicates.

Expected result (check your numbers):

Order ID City Order Date Amount
BLK-301 Pune 14-03-2025 1250
BLK-302 Pune 15-03-2025 980
BLK-303 Pune 15-03-2025 400
BLK-304 Nashik 16-03-2025 2100

4 rows. Total = 1,250 + 980 + 400 + 2,100 = ₹4,730 (Pune ₹2,630, Nashik ₹2,100). Before cleaning, the same data would add up to ₹5,980 because BLK-301 is counted twice.

Answer key (open after you try)
let
    Source   = Excel.Workbook(File.Contents("D:\Data\pune_raw.xlsx"), null, true),
    Sheet    = Source{[Item = "Sheet1", Kind = "Sheet"]}[Data],
    Headers  = Table.PromoteHeaders(Sheet, [PromoteAllScalars = true]),
    Texts    = Table.TransformColumns(Headers, {
                 {"Order ID", each Text.Upper(Text.Trim(_)), type text},
                 {"City",     each Text.Proper(Text.Trim(_)), type text}}),
    Filled   = Table.FillDown(Texts, {"City"}),
    NoRupee  = Table.ReplaceValue(Filled, "₹", "", Replacer.ReplaceText, {"Amount"}),
    NoComma  = Table.ReplaceValue(NoRupee, ",", "", Replacer.ReplaceText, {"Amount"}),
    Typed    = Table.TransformColumnTypes(NoComma, {{"Amount", Currency.Type}}),
    Dated    = Table.TransformColumnTypes(Typed, {{"Order Date", type date}}, "en-IN"),
    Distinct = Table.Distinct(Dated, {"Order ID"})
in
    Distinct

Why the order matters: Trim and UPPERCASE come before Remove Duplicates, because " blk-301" and "BLK-301" are different text until they are cleaned.

Common mistakes:

What you see Why Fix
5 rows, total ₹5,980 Remove Duplicates ran before Trim / UPPERCASE Move the Remove Duplicates step to the end
Fill Down does nothing The cell holds empty text "", not null Replace Values: blank → null first
Error in Order Date, or day and month swapped Default locale is English (United States) Change Type › Using Locale › English (India)
Sum of Amount gives an error Amount is still text Remove ₹ and commas, then set a number type

Samajla ka? Clean the key first, then remove duplicates. The order of Applied Steps is part of the answer.

Thodkyaat sangaycha tar (quick recap)

Always clean in the same order – junk rows, headers, text cleaning, values, types, duplicates. After every step, compare the row count and the total with the source. Got it? If not, do the case study (7.25) once more. Next, let's add columns.