Hello, amazing data explorer! ๐ You have already learned how to clean messy data in Modules 1 and 2. Now, we are going to become data shapers! Imagine you are a sculptor with a big block of clay. You can cut it, join pieces, and shape it into anything you want. Power Query lets you do the same with data. In this module, we will learn how to combine data from many different sources, shape it exactly the way we need, and even automate the whole process. By the end, you will be able to handle data like a true expert! Let's jump in! ๐โโ๏ธ
In a big school in Abuja, Nigeria, the principal, Mrs. Okafor, needed to combine exam results from all 30 classes. Each class teacher had sent an Excel file with marks. Mrs. Okafor was worried because she had to open each file, copy the data, and paste them into one big sheet. That would take hours! Her son, Tunde, who was 11 years old and loved computers, said, "Mummy, let me try something." He used Power Query to combine all the files from a folder with just a few clicks. He also used a parameter so that if new files were added, the query would automatically include them. In just 5 minutes, Tunde had a complete master sheet with all the results. Mrs. Okafor was so proud! ๐
This module will teach you the magic Tunde used!
Definition: Combining data from multiple files means taking information from several workbooks and putting it into one table.
Why important: Often data is split across many files (e.g., sales per month). Combining saves you from copying and pasting.
Simple explanation: It's like collecting all your Lego sets and putting all the bricks into one big box.
Real-life example: A shop owner has a separate Excel file for each day's sales. Power Query can combine them into one file.
School example: Your teacher has exam scores in separate files for each class. You can combine them.
Home example: Your family has a budget file for each year. You can combine them.
Nigerian example: A farmer has crop yield data for each month in separate files. Combine them to see the whole year.
Illustration:
File1: Jan Sales File2: Feb Sales File3: Mar Sales
\ | /
\ | /
V V V
+-----------------------------------+
| Combined Sales (All Months) |
+-----------------------------------+
Mini summary: Combining files brings scattered data together.
Definition: This is a special feature where Power Query combines all files of a certain type (e.g., Excel or CSV) inside a folder.
Why important: It's super efficient โ you don't even need to open the files.
Simple explanation: Like telling your friend to bring all the books from a shelf, not just one book.
Real-life example: You have a folder with 365 daily sales files. Power Query can combine them all.
School example: A folder with all student attendance sheets for the term.
Home example: A folder with photos (but for data, it's files!).
Nigerian example: A bank has transaction files for each branch in one folder.
Illustration:
๐ Folder โโโ Jan.csv โโโ Feb.csv โโโ Mar.csv โโโ ... [Power Query] โ One big table
Mini summary: Combining from a folder is like a bulk action.
Definition: Power Query has a built-in button called "Combine Files" that does everything automatically.
Why important: It saves you from setting up steps manually โ it's a shortcut.
Simple explanation: Like a one-click magic wand.
Real-life example: Click "Combine Files" and Power Query detects the structure.
School example: Combine all class files with one click.
Home example: Combine your allowance records.
Nigerian example: Combine branch sales files easily.
Illustration:
Get Data โ From Folder โ Combine & Transform Data
Mini summary: "Combine Files" is a quick way to merge many files.
Definition: A parameter is a value you can change easily, like a year or a product name, to make your query flexible.
Why important: Instead of editing the query every time, you change the parameter.
Simple explanation: Like a variable in a video game โ you can change it to get different results.
Real-life example: Create a parameter for "Year" โ change it from 2025 to 2026 and the query updates.
School example: Parameter for "Class" โ change to see results for different classes.
Home example: Parameter for "Month" โ change to see expenses for that month.
Nigerian example: Parameter for "Region" โ change to see data for Lagos, Abuja, or Kano.
Illustration:
Parameter: Year = 2025 Query uses Year to filter data. Change to 2026 โ Query updates automatically.
Mini summary: Parameters make queries dynamic and reusable.
Definition: You create a parameter by going to Home โ Manage Parameters โ New Parameter.
Why important: It's easy to do and very powerful.
Simple explanation: You name the parameter and give it a default value.
Real-life example: Parameter "MinSales" = 1000.
School example: Parameter "PassMark" = 70.
Home example: Parameter "Budget" = 5000.
Nigerian example: Parameter "State" = "Lagos".
Illustration:
Manage Parameters โ New Name: Year Type: Number Current Value: 2025
Mini summary: Creating parameters is simple and useful.
Definition: You can use parameters in filter, custom columns, or file paths.
Why important: This makes your query answer different questions without changing steps.
Simple explanation: Like using a variable in math โ x + 2, where x is the parameter.
Real-life example: Filter sales where Year = [Year Parameter].
School example: Show only students with Score >= [PassMark].
Home example: Show expenses where Amount <= [Budget].
Nigerian example: Filter data for [State] = "Lagos".
Illustration:
Filter Rows โ Where [Year] = [YearParam]
Mini summary: Parameters let you control your query from one place.
Definition: A function is a reusable set of steps that you can apply to different data.
Why important: Instead of writing the same steps again and again, you use a function.
Simple explanation: Like a recipe that you can use for different ingredients.
Real-life example: A function that cleans any table you give it.
School example: A function to calculate total marks for any subject.
Home example: A function to convert currencies.
Nigerian example: A function to calculate VAT on any price.
Illustration:
Function: CleanData (Input Table) โ Returns Cleaned Table Apply to Table1, Table2, Table3.
Mini summary: Functions are reusable cleaning machines.
Definition: You create a function by writing M code, but Power Query can help you create it from a query.
Why important: You can automate repetitive tasks.
Simple explanation: You build a machine that does the same job on different inputs.
Real-life example: Create a function that removes duplicates from any table.
School example: Create a function that standardises names.
Home example: Create a function that categorises expenses.
Nigerian example: Create a function that formats phone numbers.
Illustration:
Query1 (cleans data) โ Convert to Function Name: CleanFunction Parameter: InputTable
Mini summary: Functions are custom tools you build.
Definition: Once you have a function, you can invoke (call) it with different tables.
Why important: It saves time and ensures consistency.
Simple explanation: You call the function like you call a friend to help.
Real-life example: Invoke CleanFunction on SalesData.
School example: Invoke StandardiseName on student list.
Home example: Invoke CurrencyConverter on prices.
Nigerian example: Invoke PhoneFormatter on customer list.
Illustration:
Invoke Custom Function โ Select Function โ Apply
Mini summary: Using functions is like delegating work.
Definition: Dependencies show how queries are connected โ which query uses which.
Why important: If you change one query, you know which others will be affected.
Simple explanation: Like a family tree โ if grandma changes, everyone is affected.
Real-life example: Query A is used by Query B and C.
School example: ClassData is used by Report and Dashboard.
Home example: Expenses used by Summary and Chart.
Nigerian example: SalesData used by Profit and Revenue queries.
Illustration:
[BaseData] โ [CleanedData] โ [FinalReport]
| |
V V
[Backup] [Summary]
Mini summary: Dependencies help you manage your queries.
Definition: Optimising means making your query run faster and use less memory.
Why important: Large data can be slow โ you want it to be quick.
Simple explanation: Like cleaning your room quickly by putting things in the right place.
Real-life example: Only load columns you need, not all columns.
School example: Only load the student names and scores, not their photos.
Home example: Only load the current year's expenses.
Nigerian example: Only load data for the current region.
Illustration:
โ Good: Load only needed columns. โ Bad: Load all columns.
Mini summary: Optimisation makes queries faster.
Definition: Dynamic refresh means your query updates automatically when the source data changes.
Why important: You always have the latest data without doing anything.
Simple explanation: Like a news ticker that updates automatically.
Real-life example: Sales data refreshes every morning.
School example: Attendance refreshes each period.
Home example: Budget refreshes when you add new expenses.
Nigerian example: Stock data refreshes every hour.
Illustration:
Data Source โ Power Query โ Refresh (scheduled) โ Updated Report
Mini summary: Dynamic refresh keeps data current.
Definition: A workflow is a series of steps from start to finish โ load, clean, transform, combine, and output.
Why important: It gives you a structured way to handle data projects.
Simple explanation: Like a recipe โ first gather ingredients, then chop, cook, and serve.
Real-life example: Load daily files โ Clean โ Combine โ Generate report.
School example: Load class files โ Standardise โ Merge โ Calculate averages.
Home example: Load receipts โ Categorise โ Summarise by month.
Nigerian example: Load branch data โ Clean โ Combine โ Create dashboard.
Illustration:
1. Get Data (from Folder)
|
V
2. Combine Files
|
V
3. Clean & Transform
|
V
4. Group & Pivot
|
V
5. Load to Excel
Mini summary: A workflow organises your entire data process.
Definition: Error handling means managing problems when data is missing or in the wrong format.
Why important: Sometimes files are corrupt or have different structures โ you can handle it gracefully.
Simple explanation: Like when you drop a glass, you clean it up instead of crying.
Real-life example: If a file is missing, Power Query can skip it and continue.
School example: If a student's data is missing, use a default value.
Home example: If a receipt is missing, estimate the amount.
Nigerian example: If a branch file is missing, use previous month's data.
Illustration:
Try: Load File If error โ Skip file
Mini summary: Error handling makes your queries robust.
Definition: Documenting means adding notes or descriptions to your queries so others (or you) can understand them later.
Why important: After a few months, you might forget what a step does. Documentation helps.
Simple explanation: Like writing labels on storage boxes.
Real-life example: Add a comment in the M code: "This step removes duplicates".
School example: Write notes on your project steps.
Home example: Label your queries: "Jan Expenses", "Feb Expenses".
Nigerian example: Add comments to explain logic to colleagues.
Illustration:
// This step splits Full Name into First and Last // This step filters out rows with missing values
Mini summary: Documentation helps you and others understand your work.
Combine Files from a Folder:
Create a Parameter:
Use a Parameter in Filter:
Create a Function from a Query:
Optimise a Query:
[Start]
|
V
[Get Data from Folder]
|
V
[Combine Files]
|
V
[Clean & Transform]
|
V
[Load to Excel]
1. Load Files โ 2. Combine โ 3. Clean โ 4. Transform
โ โ โ โ
5. Group/Pivot โ 6. Load โ 7. Refresh (optional)
| Feature | Manual | Power Query |
|---|---|---|
| Time for 10 files | 30 minutes | 2 minutes |
| Errors | High | Low |
| Reusability | No | Yes |
| Automation | No | Yes |
| Feature | Hard-coded | Parameter |
|---|---|---|
| Change value | Edit query | Change parameter |
| Flexibility | Low | High |
| Reusability | Low | High |
Fantastic work! ๐ You have completed Module 3. You now know how to:
You are now a Power Query integration expert! You can handle data from anywhere and shape it perfectly.
| Column A | Column B |
|---|---|
| 1. Combine | A. Reusable steps |
| 2. Parameter | B. Dynamic value |
| 3. Function | C. Bring data together |
| 4. Optimise | D. Make faster |
| 5. Workflow | E. Series of steps |
Answers: 1-C, 2-B, 3-A, 4-D, 5-E
Activity: In groups, create a folder with 5 different Excel files containing fictional sales data. Each group member creates one file. Then, use Power Query to combine all files, clean the data, and create a summary table. Present your results.
Activity: Create a folder with 3 Excel files (e.g., Jan, Feb, Mar). Each file should have at least 10 rows of data. Use Power Query to combine them, then create a parameter for "Year" and filter the data accordingly. Save your query.
Project: Create a Power Query solution that combines data from at least 5 different Excel files in a folder. The files should have sales data for different regions. Clean the data, add a conditional column for "High" or "Low" sales, group by region, and create a summary. Load the final table into Excel. Document your steps.
Assignment: Your teacher will provide a folder with 10 Excel files containing student grades. Your task:
Challenge: Use Power Query to combine data from a folder of CSV files. But some files have extra columns. Write a function that cleans any file you give it, and then apply that function to all files while combining. This will test your skills in parameters and functions. Show your final combined table.
All answers are provided within each exercise section above.
In Module 4, we will dive into Advanced Data Analysis with Power Query โ we will learn about complex calculations, data modelling, and creating interactive dashboards. We will also explore how to use Power Query with Power BI. You are now ready to take on more complex data challenges. Keep practising and stay curious!
๐ End of Module 3 โ You are now a data combining champion! ๐