Hello again, data explorer! π In Module 1, we learned what Power Query is and how to do basic cleaning. Now, we will go deeper. We will learn how to fix common problems like extra spaces, wrong dates, and mixed text. We will also learn how to split columns and combine data from different sources. By the end of this module, you will be able to clean data like a professional! Let's dive in! πββοΈ
In a small bakery in Ibadan, Nigeria, the baker, Mr. Ade, had a problem. He kept records of his daily bread sales, but his data was messy. Some dates were written as "12/05/2025" and others as "May 12, 2025". Some customer names had extra spaces like " Chidi ". He also had a column called "Full Name" but he needed separate "First Name" and "Last Name". He spent hours fixing these problems by hand. Then his daughter, Ngozi, who had just learned Power Query, said, "Daddy, let me help!" She used Power Query to trim spaces, fix dates, split names, and even combine data from two different files. In just a few minutes, everything was perfect. Mr. Ade was amazed and gave Ngozi an extra piece of cake! π
This module will teach you all the tricks Ngozi used!
Definition: Trim means removing unwanted spaces from the beginning or end of text.
Why important: Extra spaces can make it hard to search or match data. "Chidi" and "Chidi " are not the same to a computer.
Simple explanation: It's like cleaning the edges of a paper before putting it in a frame.
Real-life example: A customer list has " Ada " β trim makes it "Ada".
School example: A teacher trims student names before printing certificates.
Home example: Your mom trims the grocery list to remove extra spaces.
Nigerian example: A bank trims account holder names to avoid mismatches.
Illustration:
Before: " Bola " β After: "Bola"
Mini summary: Trim removes extra spaces from text.
Definition: Clean removes characters that are not visible, like line breaks or special symbols.
Why important: These characters can cause errors in calculations or sorting.
Simple explanation: Like wiping dust off a table before placing a book.
Real-life example: Data copied from a website may have hidden symbols β Clean removes them.
School example: A project list from a website has weird characters β Clean fixes it.
Home example: A contact list copied from an email has extra symbols.
Nigerian example: A farmer's crop data from a PDF has hidden line breaks.
Illustration:
Before: "Mangoπ" (with hidden symbol) β After: "Mango"
Mini summary: Clean removes invisible characters.
Definition: Dates can be written in many ways. Power Query can change them to a standard format.
Why important: If dates are in different formats, you cannot sort or calculate correctly.
Simple explanation: It's like making sure all your friends write their birthdays the same way: DD/MM/YYYY.
Real-life example: Change "2025-12-31" to "31-Dec-2025".
School example: Make all exam dates look the same in the school calendar.
Home example: Fix the dates on your family's holiday photos.
Nigerian example: A school in Enugu standardises admission dates.
Illustration:
Before: 12/31/2025 β After: 31/12/2025 (consistent)
Mini summary: Standardise date formats for consistency.
Definition: Splitting means taking one column and dividing it into two or more columns.
Why important: Sometimes one column has too much information, like "Chidi Okonkwo" β we want "Chidi" and "Okonkwo".
Simple explanation: Like cutting a sandwich into two halves.
Real-life example: Split "Full Name" into "First Name" and "Last Name".
School example: Split "Subject-Grade" into "Subject" and "Grade".
Home example: Split "Address" into "City" and "Street".
Nigerian example: Split "Lagos-Nigeria" into "City" and "Country".
Illustration:
Before: "Chidi Okonkwo" β After: "Chidi" | "Okonkwo"
Mini summary: Split columns to separate information.
Definition: Combining merges two or more columns into one.
Why important: Sometimes you need a full name or full address from separate parts.
Simple explanation: Like joining two puzzle pieces to make a bigger piece.
Real-life example: Merge "First Name" and "Last Name" into "Full Name".
School example: Merge "Class" and "Section" into "Class-Section".
Home example: Merge "Street" and "Number" into "Address".
Nigerian example: Merge "LGA" and "State" into "Location".
Illustration:
Before: "Chidi" | "Okonkwo" β After: "Chidi Okonkwo"
Mini summary: Combine columns to create new information.
Definition: Replace Values changes specific text or numbers to something else.
Why important: You might have abbreviations or errors that need to be corrected.
Simple explanation: Like using a white-out pen to fix a mistake.
Real-life example: Change "N/A" to "0".
School example: Change "Absent" to "A".
Home example: Change "Kg" to "Kilogram".
Nigerian example: Change "LAG" to "Lagos".
Illustration:
Before: "N/A" β After: "0"
Mini summary: Replace values to fix errors or standardise.
Definition: A conditional column creates a new column based on a condition (if-then logic).
Why important: You can categorise data automatically.
Simple explanation: Like saying, "If it rains, take an umbrella; else, take a hat."
Real-life example: If sales > 1000, mark "High"; else "Low".
School example: If score β₯ 70, mark "Pass"; else "Fail".
Home example: If price > 500, mark "Expensive"; else "Cheap".
Nigerian example: If crop yield > 500kg, mark "Good Harvest".
Illustration:
Sales | Category 1500 | High 700 | Low
Mini summary: Conditional columns add categories based on rules.
Definition: Group By combines rows with the same value in a column and calculates something like sum, average, or count.
Why important: It summarises large data so you can see totals.
Simple explanation: Like grouping your toys by colour and counting how many of each colour.
Real-life example: Group sales by product to see total sales per product.
School example: Group students by class and count how many in each class.
Home example: Group expenses by category (food, rent) and sum them.
Nigerian example: Group farm produce by crop and sum the weight.
Illustration:
Product | Sales Mango | 100 Mango | 150 Orange | 200 Group By Product β Mango:250, Orange:200
Mini summary: Group By summarises data by categories.
Definition: Pivot turns a column's values into multiple columns.
Why important: It makes data wider and easier to compare.
Simple explanation: Like turning a list of months into separate columns for January, February, etc.
Real-life example: Pivot months to see each month as a column.
School example: Pivot subjects to see each subject as a column with grades.
Home example: Pivot types of chores to see time spent per type.
Nigerian example: Pivot regions to see sales per region.
Illustration:
Before: Month | Sales
Jan | 100
Feb | 200
After: Jan | Feb
100 | 200
Mini summary: Pivot makes data wider.
Definition: Unpivot is the opposite of pivot β it turns multiple columns into rows.
Why important: Sometimes you need data tall (long) instead of wide.
Simple explanation: Like taking a table with Jan, Feb, Mar and turning it into a list of Month-Sales.
Real-life example: Unpivot monthly sales columns into a single column of months.
School example: Unpivot subject columns into a list of subjects.
Home example: Unpivot expense columns into a list of expenses.
Nigerian example: Unpivot crop yields by month.
Illustration:
Before: Jan | Feb | Mar
100 | 200 | 150
After: Month | Sales
Jan | 100
Feb | 200
Mar | 150
Mini summary: Unpivot makes data taller (more rows).
Definition: Merging joins two queries (tables) from different sources using a common column.
Why important: You often have data in separate files β merging brings them together.
Simple explanation: Like sticking two photos together to make a bigger picture.
Real-life example: Merge customer data from Excel with order data from a database.
School example: Merge student list from one file with test scores from another.
Home example: Merge your toy list with a price list from a website.
Nigerian example: Merge school attendance from Excel with exam results from CSV.
Illustration:
Query1: StudentID, Name Query2: StudentID, Score Merge β StudentID, Name, Score
Mini summary: Merging combines queries from different sources.
Definition: Appending stacks two queries (tables) on top of each other.
Why important: If you have monthly sales in separate files, you can combine them into one.
Simple explanation: Like stacking building blocks.
Real-life example: Append January sales query with February sales query.
School example: Append test scores from Class A and Class B.
Home example: Append your allowance records from two years.
Nigerian example: Append daily sales from all branches.
Illustration:
Query Jan: Ada, 100 Query Feb: Bola, 200 Append β Ada, 100; Bola, 200
Mini summary: Append stacks queries vertically.
Definition: A custom column is a new column that you create using a formula.
Why important: You can calculate new data, like total price = quantity * price.
Simple explanation: Like using a calculator to add numbers and writing the answer in a new column.
Real-life example: Create "Total Sales" = Quantity * Unit Price.
School example: Create "Total Score" = Test1 + Test2.
Home example: Create "Total Cost" = Items * Price.
Nigerian example: Create "Total Harvest" = Bags * Weight.
Illustration:
Quantity | Price | Total (custom) 2 | 500 | 1000
Mini summary: Custom columns let you create new data with formulas.
Definition: M is the language behind Power Query. It writes the steps for you.
Why important: You can see the code and learn to write your own advanced steps.
Simple explanation: It's like the recipe behind your favourite dish. Power Query writes it for you.
Real-life example: When you click a button, Power Query writes M code in the background.
School example: Like the teacher writing notes on the board β M is the notes.
Home example: The instructions for a toy are like M code.
Nigerian example: A recipe for jollof rice is like M code β step-by-step.
Illustration:
let
Source = Excel.Workbook(...),
Table1 = Source{[Item="Sheet1"]}[Data]
in
Table1
Mini summary: M is the code behind your cleaning steps.
Definition: Refreshing updates your query to get the latest data.
Why important: If new data comes in, you can refresh to see it without redoing all steps.
Simple explanation: Like turning on the tap to get fresh water.
Real-life example: You refresh your sales query to include today's sales.
School example: Refresh attendance to see who is present today.
Home example: Refresh your chore list to see new tasks.
Nigerian example: Refresh crop data after a new harvest.
Illustration:
Click Refresh β New data appears
Mini summary: Refresh brings in new data.
Trim and Clean:
Split Column:
Combine Columns:
Replace Values:
Conditional Column:
Group By:
Pivot:
Unpivot:
Merge Queries:
Append Queries:
Custom Column:
[ Load Data ]
|
V
[ Trim & Clean ]
|
V
[ Split/Combine ]
|
V
[ Replace Values ]
|
V
[ Conditional Column ]
|
V
[ Group / Pivot ]
|
V
[ Merge / Append ]
|
V
[ Load to Excel ]
1. Trim β 2. Clean β 3. Split β 4. Combine
β β β β
5. Replace β 6. Conditional β 7. Group By
β β β
8. Pivot β 9. Unpivot β 10. Merge/Append
| Feature | Pivot | Unpivot |
|---|---|---|
| Effect | Makes data wider | Makes data taller |
| Columns | Increases | Decreases |
| Rows | Decreases | Increases |
| Use case | Comparative analysis | Normalisation |
Congratulations! π You have completed Module 2. You now know how to:
You are now a Power Query cleaning expert! Keep practising with different datasets.
| Column A | Column B |
|---|---|
| 1. Trim | A. Remove invisible characters |
| 2. Clean | B. Divide a column |
| 3. Split | C. Remove extra spaces |
| 4. Combine | D. Merge columns |
| 5. Replace Values | E. Change specific text |
Answers: 1-C, 2-A, 3-B, 4-D, 5-E
Activity: In groups, find a messy dataset online (e.g., weather data). Load it into Power Query and apply at least 10 cleaning and transformation steps. Present your final table.
Activity: Create a dataset of 20 fictional students (Name, Subject, Score). Include extra spaces, inconsistent dates, and duplicate values. Clean and transform it using Power Query.
Project: Collect data from 10 of your classmates (Name, Age, Favourite Subject, Test Score). Clean it using Power Query: trim, split name, conditional column for pass/fail, group by subject to get average scores. Load the final report.
Assignment: Download a CSV file of sales data from your teacher. Load it into Power Query. Apply the following:
Submit the cleaned file.
Challenge: Use Power Query to get data from a web page (e.g., Wikipedia table). Clean the data: remove duplicates, split columns, and create a conditional column. Then merge it with another table you have. Show your final result.
All answers are provided within each exercise section above.
In Module 3, we will learn about Advanced Data Analysis β we will use Power Query to perform complex calculations, create dynamic reports, and automate workflows. We will also learn how to optimise queries for speed. Keep practising all the steps from Modules 1 and 2. You are doing great!
π End of Module 2 β Keep cleaning and exploring! π