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):
- Type the rows in Excel, save, and load with Get data › Excel workbook › Transform Data.
- Order ID: Transform › Format › Trim, then UPPERCASE.
- City: Transform › Format › Trim, then Capitalize Each Word.
- City: Transform › Fill › Down.
- Amount: Replace Values
₹→ nothing, then,→ nothing. Change type to Fixed decimal number. - Order Date: right-click › Change Type › Using Locale… › Date, English (India).
- 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.
नेहमी एकाच क्रमाने क्लीन करा – जंक रो, हेडर्स, टेक्स्ट क्लीनिंग, व्हॅल्यूज, टाइप्स, डुप्लिकेट्स. प्रत्येक स्टेपनंतर रो काउंट आणि टोटल सोर्सशी मॅच करून बघा. समजलं का? नसेल तर केस स्टडी (7.25) पुन्हा एकदा करा. आता पुढे जाऊया कॉलम्स ॲड करायला.
हमेशा एक ही क्रम में क्लीन करो – जंक रो, हेडर्स, टेक्स्ट क्लीनिंग, वैल्यूज़, टाइप्स, डुप्लीकेट्स. हर स्टेप के बाद रो काउंट और टोटल को सोर्स से मैच करके देखो. समझ आया? नहीं तो केस स्टडी (7.25) एक बार फिर करो. अब आगे चलते हैं कॉलम्स ऐड करने की ओर.