Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
โ† Introduction to Power BI ยท Lesson 5 of 9

Module Four

๐Ÿ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
5
Module 4: Cleaning and Preparing Data with Power Query

Module 4: Cleaning and Preparing Data with Power Query

4.1 Introduction

Welcome to Module 4!

In the previous module, you learned how to connect Power BI to Excel files, CSV files, and databases. You also learned how to import information into Power BI.

But what happens when the information you import contains mistakes?

Imagine a school in Ibadan gives you an Excel file containing the examination results of 500 students. When you open the file, you discover some problems:

  • Some students appear more than once.
  • Some students have no examination scores.
  • Some names have unnecessary spaces.
  • Some scores are stored as text instead of numbers.
  • Some columns have confusing names.

If you create a report using incorrect information, your results may also be incorrect.

This is why you need to clean and prepare your data before analysing it.

What you will learn:
  • What Power Query is.
  • How to open Power Query Editor.
  • How to remove duplicate records.
  • How to handle missing values.
  • How to change data types.
  • How to rename columns.
  • How to split and merge columns.
  • How to filter and sort information.
  • How to apply changes to your data.

4.2 What Is Power Query?

Power Query is a data preparation tool available in Power BI and other Microsoft products.

It helps you collect, clean, organise, and transform information before using it for analysis.

Think of Power Query as a cleaning room for your data.

Imagine you buy vegetables from a market. Before cooking them, you wash them, remove unwanted parts, and arrange them properly.

Power Query does something similar with information. It helps remove unwanted records, correct mistakes, and arrange data properly.

Example

Imagine you import this student information into Power BI:

Student Name Score Class
David85JSS 2
Mary92JSS 2
David85JSS 2
John(Blank)JSS 2

There are two problems:

  • David appears twice.
  • John's score is missing.

Power Query can help you identify and handle these problems.

4.3 Understanding the Power Query Editor

The Power Query Editor is the workspace where you clean and transform your data.

To open it:

  1. Open Power BI Desktop.
  2. Go to the Home tab.
  3. Click Transform Data.
  4. Power Query Editor will open in a new window.

Inside Power Query Editor, you will find different sections.

1. Ribbon

The Ribbon contains commands for cleaning, transforming, and managing data.

2. Queries Pane

The Queries pane displays the tables or data sources you have opened in Power Query.

3. Data Preview Area

This area displays your information in rows and columns so you can inspect it before loading it into Power BI.

4. Query Settings

The Query Settings pane displays the properties of your query and the steps you have performed.

5. Applied Steps

Applied Steps is a list of the changes you have made to your data.

For example, if you remove duplicates and rename a column, Power Query records these actions as steps.

Remember: Power Query usually keeps your original source file unchanged. It records transformation steps that are applied when the query is refreshed or evaluated.

4.4 Removing Duplicate Records

A duplicate record is information that appears more than once when it should appear only once.

Imagine a school has a student register. David's name appears twice even though he is only one student.

This can cause problems when calculating the number of students in the school.

Example of Duplicate Records

Student Score
David85
Mary92
David85
John70

David's record appears twice.

How to Remove Duplicates

  1. Open Power Query Editor.
  2. Select the column or columns you want to check.
  3. Go to the Home tab or right-click the selected column.
  4. Choose Remove Duplicates.
  5. Power Query will remove rows that have duplicate values based on the selected column or columns.

Important: Be careful when choosing columns. If you select only Student Name, Power Query may remove records where the same student has different examination results. For examination records, you may need to select several columns or use a unique student ID to identify true duplicates.

4.5 Handling Missing and Empty Values

Sometimes, a data file contains empty spaces where information should be.

These are called missing values or blank values.

For example, a student may have a name and class but no examination score.

Student Score
David85
Mary92
John(Blank)

John's score is missing. What should you do?

You have different options depending on why the information is missing.

Option 1: Remove the Row

If the record is not needed and removing it will not affect your analysis, you may remove the row.

Option 2: Replace the Missing Value

If you have a reliable source for the missing information, you can enter the correct value.

Option 3: Keep the Blank Value

Sometimes, it is better to leave a value blank rather than guess. For example, you should not invent a student's examination score.

How to Remove Blank Rows

  1. Open Power Query Editor.
  2. Find the column containing the missing values.
  3. Click its filter arrow.
  4. Look for the blank or null option.
  5. Uncheck the blank value if you want to exclude those rows.
  6. Click OK.

Always check why information is missing before removing it.

4.6 Changing Data Types

Every column in a dataset should have an appropriate data type.

A data type tells Power BI what kind of information is stored in a column.

For example:

  • Student Name should usually be Text.
  • Age should usually be a Whole Number.
  • Price may be a Decimal Number or Fixed Decimal Number.
  • Examination Date should be Date.

Common Data Types

Data Type Meaning Example
TextLetters and words.David
Whole NumberNumbers without decimal places.25
Decimal NumberNumbers with decimal places.25.75
DateCalendar dates.26/11/2026
Date/TimeA date and time together.26/11/2026 10:30 AM
True/FalseA value that is either true or false.True

How to Change a Data Type

  1. Open Power Query Editor.
  2. Select the column you want to change.
  3. Find the data type icon beside the column name.
  4. Click the icon or use the Data Type option on the Ribbon.
  5. Select the correct data type.
  6. Confirm the change if Power BI asks you to.

Example: If a Score column contains 85, 90, and 75 but is recognised as Text, change it to Whole Number so it can be used correctly in calculations.

4.7 Renaming Columns and Tables

Sometimes, columns have names that are difficult to understand.

Imagine you import a file with these column names:

  • Column1
  • Column2
  • Column3

These names do not tell you what the information means.

You can rename them to:

  • Student Name
  • Age
  • Examination Score

How to Rename a Column

  1. Open Power Query Editor.
  2. Find the column you want to rename.
  3. Double-click the column heading or right-click it.
  4. Select Rename.
  5. Enter the new name.
  6. Press Enter.

Clear column names make your data easier to understand.

4.8 Splitting and Merging Columns

Power Query allows you to split one column into multiple columns or combine information from different columns.

A. Splitting Columns

Splitting means dividing information in one column into separate columns.

Imagine a school has a column containing students' full names.

Full Name
David Johnson
Mary James
John Peter

You may want to separate the first name from the surname.

After splitting, your table may look like this:

First Name Surname
DavidJohnson
MaryJames
JohnPeter

How to Split a Column

  1. Select the column you want to split.
  2. Go to the Transform tab.
  3. Click Split Column.
  4. Choose By Delimiter.
  5. Select the space character as the delimiter.
  6. Choose the appropriate splitting option.
  7. Click OK.

B. Merging Columns

Merging means combining information from two or more columns into one column.

For example, imagine you have:

First Name Surname
DavidJohnson
MaryJames

You can combine the two columns to create a Full Name column.

How to Merge Columns

  1. Select the columns you want to combine.
  2. Go to the Transform tab.
  3. Click Merge Columns.
  4. Choose a separator, such as a space.
  5. Enter a name for the new column.
  6. Click OK.

4.9 Filtering and Sorting Data

Filtering and sorting help you organise information so you can find what you need.

A. Filtering Data

Filtering means displaying only the records that match certain conditions.

Imagine a school has students in JSS 1, JSS 2, and JSS 3. You want to see only the JSS 2 students.

You can use a filter to display only records where Class equals JSS 2.

How to Filter Data

  1. Open Power Query Editor.
  2. Find the column you want to filter.
  3. Click the small filter arrow beside the column name.
  4. Select the values you want to keep.
  5. Click OK.

B. Sorting Data

Sorting means arranging information in a particular order.

For example, you can arrange students' scores from the highest to the lowest.

There are two common sorting orders:

  • Ascending: Arranges values from smallest to largest or A to Z.
  • Descending: Arranges values from largest to smallest or Z to A.

How to Sort Data

  1. Select the column you want to sort.
  2. Click the filter arrow beside the column name.
  3. Select Sort Ascending or Sort Descending.
  4. Power Query will arrange the records.

4.10 Applying Changes to Your Data

After cleaning and preparing your data, you need to send the changes back to Power BI Desktop.

To do this:

  1. Check the transformations you have made.
  2. Go to the Home tab in Power Query Editor.
  3. Click Close & Apply.
  4. Wait for Power BI to apply the changes.
  5. Your prepared data will now be available in Power BI Desktop.

Power Query keeps a record of the transformation steps. When you refresh your data, Power BI can run those steps again on the updated source data.

Remember: Cleaning your data is important because incorrect or poorly organised information can lead to misleading reports.

4.11 Practical Project: Clean a Student Records Table

Project: Prepare Student Examination Records

Imagine a school in Ibadan gives you the following records. Your job is to clean the information using Power Query.

Student Name Class Score
DavidJSS 285
MaryJSS 292
DavidJSS 285
JohnJSS 2(Blank)
SarahJSS 378

Your tasks:

  1. Enter the information into an Excel worksheet.
  2. Save the file as Student Records.xlsx.
  3. Import the file into Power BI Desktop.
  4. Click Transform Data to open Power Query Editor.
  5. Check for duplicate records.
  6. Decide how to handle John's missing score. Do not invent a score.
  7. Check that the Score column uses a suitable numeric data type.
  8. Rename any confusing column headings.
  9. Filter the records to display only JSS 2 students.
  10. Click Close & Apply.

Challenge Questions:

  1. How many records were in the original table?
  2. Which record was duplicated?
  3. Why should you not guess John's examination score?
  4. Why is it important to check data types?
  5. What happens when you click Close & Apply?

4.12 Important Terms to Remember

Term Simple Meaning
Power QueryA tool for collecting, cleaning, and transforming data.
Power Query EditorThe workspace where you prepare your data.
DuplicateA record or value that appears more than once.
Missing ValueInformation that is empty or unavailable.
Data TypeThe kind of information stored in a column.
FilteringDisplaying only records that match selected conditions.
SortingArranging information in a particular order.
TransformationChanging data into a more useful format.
Applied StepsA record of the changes made to a query.
Close & ApplyApplies the transformations and returns to Power BI Desktop.

4.13 Knowledge Check

Choose the correct answer for each question.

  1. What is Power Query used for?
    A. Playing music
    B. Cleaning and transforming data
    C. Drawing cartoons
    D. Sending text messages
  2. Where do you perform data cleaning in Power BI?
    A. Power Query Editor
    B. Windows Calculator
    C. Microsoft Paint
    D. File Explorer
  3. What is a duplicate record?
    A. A new computer
    B. An empty folder
    C. Information that appears more than once
    D. A chart title
  4. What is a missing value?
    A. A colourful chart
    B. A computer password
    C. A saved report
    D. Information that is empty or unavailable
  5. Which data type is suitable for a student's name?
    A. Date
    B. Text
    C. Whole Number
    D. True/False
  6. Which data type is suitable for an examination score such as 85?
    A. Whole Number
    B. Text only
    C. Date
    D. Image
  7. What does filtering data mean?
    A. Deleting Power BI
    B. Changing the computer screen
    C. Displaying records that match selected conditions
    D. Printing every record
  8. What does sorting data mean?
    A. Hiding all information
    B. Removing every column
    C. Closing a report
    D. Arranging information in a particular order
  9. What does splitting a column do?
    A. Deletes the entire table
    B. Divides information into separate columns
    C. Closes Power BI
    D. Removes all records
  10. What does Close & Apply do?
    A. Applies data transformations and returns to Power BI Desktop
    B. Deletes the source file
    C. Turns off the computer
    D. Opens a web browser

Module 4 Summary

In this module, you learned how to clean and prepare information using Power Query. You discovered how to remove duplicates, handle missing values, change data types, rename columns, split and merge information, and filter and sort records.

You also learned how to apply your changes using Close & Apply.

Remember, good data preparation helps you create more accurate and useful reports.

Coming Up in Module 5

Creating Charts and Data Visualisations: You will learn how to turn your prepared data into bar charts, column charts, line charts, pie charts, tables, cards, and maps. You will also discover how to choose the right chart for different types of information.

๐Ÿ† Get Certified

๐Ÿ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (โ‚ฆ2,000 or 20,000 coins), and get a verified certificate with your name on it.

๐ŸŽ“ Sign Up to Get Certified
๐Ÿ› ๏ธ Practice Tools
Hands-on simulators & labs - subscription required.
โ†’
๐ŸŽฏ Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
โ†’