Courses Learn Blog Contact
Get Started →
Lesson 3

Day 2: The Power Query Editor and Data Cleaning

Applied Steps, data types with the right locale, Trim, Replace Values, Remove Duplicates and Filter Rows.

Webbo3 Power BI Cohort 1 13 min read Free

Webbo3 Power BI · Cohort 1 · Day 2 of 16

Day 2: The Power Query Editor and Data Cleaning

Seven station managers typed this sheet seven different ways. Today you make it one clean table.

By the end of today you can

  • Find your way round the Power Query Editor and read Applied Steps
  • Use column profiling to see problems before fixing them
  • Set data types yourself, and read three date formats with the right locale
  • Clean names with Trim, Capitalize Each Word and Replace Values
  • Fill blanks, remove duplicates and filter out impossible rows

Yesterday you saw the mess. Today you clean Sales_2023 step by step, and every step is a click, not a line of code.

Open your Day 1 file and click Transform Data. Everything today happens in the Power Query Editor, on the Sales_2023 query.

1. The Power Query Editor

Definition

The Power Query Editor is the kitchen of Power BI: a separate window where you clean and shape data before it reaches the report. Nothing you do here changes the workbook. Every change is recorded as a step, and the steps run again, in order, every time you refresh.

Real-Life Example

A recipe card. You do not wash the same vegetables by hand every day; you write the method down once, and anyone can follow it tomorrow with fresh vegetables. Applied Steps is that recipe card.

Types: The Parts of the Window

PartWhereWhat it is for
Queries paneLeftEvery table you brought in, one query each
PreviewMiddleThe first 1,000 rows of the selected query, after the selected step
Applied StepsRight, under Query SettingsThe recipe: every change, in order. Click one to see the data as it was then
Formula barAbove the previewThe selected step written out. You can ignore it in this course
RibbonTopHome, Transform and Add Column hold every button you need
Deleting a Step

Click the X beside a step to delete it. Deleting a step in the middle can break the steps after it, so Power BI asks first. Delete from the bottom up when you can.

Column Profiling: Seeing Problems Before Fixing Them

Click path

1.View › Tick Column quality › Tick Column distribution › Tick Column profile
2.Bottom left of the window › Column profiling based on entire data set

Column distribution shows, under each header, how many distinct values the column has. For a column like StationName, which should hold seven stations, that number is your first warning.

What we are looking atWe want to see how many distinct values each text column really holds across the whole sheet, and how many cells are empty, before anything is cleaned.
Column profile, entire data set
ColumnDistinct valuesShould beEmpty cells
StationName27170
ProductName17250
AttendantName46817320
PaymentMethod2430
Date8
Picture This

Picture the recipe card pinned above the sink: the method written once, followed every time.

2. Data Types, and a Date Column Typed Three Ways

Definition

A column's data type tells Power BI what kind of value it holds, which decides what it can do with it. Text can be searched but not added. A number can be added. A date can be sorted by time and split into years and months. The badge on each column header shows its current type.

Real-Life Example

A bank teller sorts what you hand over: notes go in the counter, cheques to clearing, forms to the desk. Hand them a cheque as if it were cash and nothing works. A date stored as text is that cheque in the note counter.

Types: The Ones You Will Use

TypeBadgeUse it forIn Sales_2023
TextABCNames, codes, IDsTransactionID, StationName, ProductName, AttendantName, PaymentMethod
Decimal Number1.2Anything that can have a fractionQuantity (9.7 litres), UnitPrice_NGN, TotalAmount_NGN
Whole Number1²3Counts with no fractionNot needed today
DateDATECalendar daysDate
Date/TimeD/TA day and a timeNot in this dataset

The Date Problem

Each station manager typed the date the way their own phone or laptop does. The Date column holds three formats, and some rows have no date at all:

What we are looking atWe want to count every way the Date column was typed in Sales_2023.
Date column, by format
How the date was typedRows
Year first: 2023-10-131,763
Day first: 13/10/2023941
In words: October 13, 2023477
Blank8
Total3,189

Year first and in-words dates can only mean one thing. Day first is the dangerous one, because 05/06/2023 is 5 June to a Nigerian or British reader and May 6 to an American one. Power BI reads dates using your laptop's region unless you tell it otherwise.

What we are looking atWe want to see what would happen to the 941 day-first dates if Power BI read them with United States rules (month first), the default on many laptops.
Day-first dates read with United States rules
What happensRowsWhy
Error581The first number is above 12, so it cannot be a month
Silently wrong326The first number is 12 or less, so day and month swap
Correct by luck34Day and month are the same number
Total941

The errors are the good news: you can see them. The 326 silently wrong dates are the disaster, because nothing looks broken. A June sale lands in May and every monthly total is wrong. The fix is to tell Power BI which country's rules to use.

Setting the Types Yourself

Changed Type with Locale

1.Applied Steps: click the X beside "Changed Type" to delete Power BI's guess
2.Right-click the Date header › Change Type › Using Locale... › Data Type: Date › Locale: English (United Kingdom) › OK
3.Select Quantity › Ctrl+click UnitPrice_NGN and TotalAmount_NGN › Transform › Data Type: Decimal Number
4.Select TransactionID and the four name columns › Data Type: Text
What we are checkingWe want to see the Date column after it is read with United Kingdom rules: all three formats become real dates, and the blank ones stay empty (null).
Preview after Changed Type with Locale
ABC 123TransactionIDDATEDateABC 123StationNameABC 123ProductNameABC 123AttendantName1.2Quantity1.2UnitPrice_NGN1.2TotalAmount_NGNABC 123PaymentMethod
1TXN-2023-00038313/02/2023Bodija·Filling·Station·PMS (PETROL)Amina Nwosu9.7187.41,817.78Cash·
2TXN-2023-00246813/10/2023BODIJA FILLING STATIONEngine OilSegun·Adeyemi·23,402.876,805.74CASH·
3TXN-2023-00216110/09/2023Bodija Filling Stationpms (petrol)bisi chukwu39.7612.6124,320.62POS·
4TXN-2023-00278920/11/2023gra filling stationpms (petrol)KEMI BALOGUN41638.4226,175.22CASH
5TXN-2023-00110305/05/2023Wuse Filling StationPMS (Petrol)Halima·Umeh·36.1179.686,486.45Cash·
6TXN-2023-00114209/05/2023INDEPENDENCE LAYOUT FILLING STATIONGreaseChinwe Chukwu31,202.43,607.2pos
7TXN-2023-00213907/09/2023Bodija Filling StationPMS (PETROL)segun adeyemi44.5629.9328,031.88POS
8TXN-2023-00310127/12/2023···sabon·gari·filling·station·····grease····Ifeanyi·Suleiman··31,215.033,645.09CASH
9 COLUMNS, 3,189 ROWS · first 8 shown

English (United Kingdom) reads day first, and it also understands the year-first and in-words formats. Check the column quality bar under Date: it should show 0% Error and 0.3% Empty, which is the 8 rows with no date.

If You Do See Errors

Click one Error cell. The panel at the bottom shows the text that failed. Almost always the step was set to English (United States) by mistake. Delete the step and do it again with the right locale; never just remove the error rows.

Picture This

Picture the teller who asks where a cheque is from before she reads the date on it.

3. Cleaning Names: Trim, Capitalize Each Word and Replace Values

Definition

Three buttons fix almost every badly typed name. Trim removes spaces at the start and end of each cell. Capitalize Each Word makes the first letter of every word capital and the rest lower case. Replace Values swaps one exact value for another.

Real-Life Example

Name tags at an event, written by seven different people. One wrote in capitals, one in small letters, one left a gap before the name. Before you can sort them into a register, someone has to rewrite them the same way.

Types: The Three Fixes

FixWhereWhat it changesExample
TrimTransform, Format, TrimSpaces at the start and end only" Wuse Filling Station " becomes "Wuse Filling Station"
Capitalize Each WordTransform, FormatEvery word: capital first letter, rest lower case"WUSE FILLING STATION" becomes "Wuse Filling Station"
Replace ValuesTransform, Replace ValuesOne exact value into another"Pos" becomes "POS"

Step 1: Trim

Click path

1.Select StationName › Ctrl+click ProductName, AttendantName and PaymentMethod › Transform › Format › Trim

Step 2: Capitalize Each Word

Click path

1.Keep the same four columns selected › Transform › Format › Capitalize Each Word
What we are checkingWe want to see how many distinct values each column has after each step, to watch the mess collapse.
Distinct values after each step
ColumnBeforeAfter TrimAfter Capitalize Each WordShould be
StationName2712177
ProductName1721555
AttendantName468511717
PaymentMethod24833

The counts are right, but look at the actual values. Capitalize Each Word does not know which words are abbreviations:

What we are looking atWe want to see the station, product and payment values left after Capitalize Each Word, to find the ones it spelled wrong.
Values after Capitalize Each Word
ColumnValues nowWhat the master sheet says
StationNameBodija Filling Station, Gra Filling Station, Ikeja Filling Station, Independence Layout Filling Station, Lekki Filling Station, Sabon Gari Filling Station, Wuse Filling StationGRA Filling Station, in capitals
ProductNameAgo (Diesel), Dpk (Kerosene), Engine Oil, Grease, Pms (Petrol)PMS (Petrol), AGO (Diesel), DPK (Kerosene)
PaymentMethodCash, Pos, TransferPOS

Step 3: Replace Values, Five Times

GRA, PMS, AGO, DPK and POS are abbreviations, so they should stay in capitals. One Replace Values step fixes each one. Tick Match entire cell contents, or "Pos" would also be replaced inside any longer word that happened to contain it.

Click path

1.Select StationName › Transform › Replace Values › Value To Find: Gra Filling Station › Replace With: GRA Filling Station › Advanced options: tick Match entire cell contents › OK
ColumnValue To FindReplace With
StationNameGra Filling StationGRA Filling Station
ProductNamePms (Petrol)PMS (Petrol)
ProductNameAgo (Diesel)AGO (Diesel)
ProductNameDpk (Kerosene)DPK (Kerosene)
PaymentMethodPosPOS

After the five steps, every name is spelled exactly as it is on the master sheets. That matters more than it looks: on Day 5 you join these names to Station_Master and Product_Master, and a join only matches names that are identical, letter for letter.

Picture This

Picture the seven name tags rewritten in one hand, with the abbreviations still in capitals.

4. Blank Attendants: Replacing null

Definition

An empty cell in Power Query is null: no value at all, which is different from a space or a zero. Replace Values can put a word in its place.

Real-Life Example

320 sales in 2023 have no attendant name. They are not mistakes: some pumps run unmanned or self-service. Leaving the cell empty makes those sales disappear from any "by attendant" chart; giving them a name keeps them counted.

Click path

1.Select AttendantName › Transform › Replace Values › Value To Find: null › Replace With: Unmanned › OK

Type the word null exactly, in lower case. It is Power Query's name for an empty cell.

5. Removing Rows That Cannot Be Used

Definition

Some rows have to go: rows with no date cannot be placed in any month, rows entered twice would be counted twice, and a quantity of zero or less is not a sale. Each gets its own step.

Real-Life Example

Counting the day's receipts. A receipt with no date goes to the manager, a photocopy of a receipt already counted goes in the bin, and a refund slip is not a sale.

Types: Three Ways Rows Are Removed

ProblemButtonRows removed from Sales_2023
No dateDate header dropdown, untick (null)8
The same log submitted twiceHome, Remove Rows, Remove Duplicates (with every column selected)47
Quantity zero or negativeQuantity dropdown, Number Filters, Greater Than 018

Duplicates

What we are looking atWe want to see one duplicate for ourselves: transaction TXN-2023-002468, which appears twice, every column the same.
Sales_2023 filtered to TXN-2023-002468
ABC 123TransactionIDABC 123DateABC 123StationNameABC 123ProductNameABC 123AttendantNameABC 123QuantityABC 123UnitPrice_NGNABC 123TotalAmount_NGNABC 123PaymentMethod
1TXN-2023-00246813/10/2023BODIJA FILLING STATIONEngine OilSegun·Adeyemi·23,402.876,805.74CASH·
2TXN-2023-00246813/10/2023BODIJA FILLING STATIONEngine OilSegun·Adeyemi·23,402.876,805.74CASH·
9 COLUMNS, 2 ROWS

Select every column first (Ctrl+A in the preview) so Remove Duplicates compares whole rows. A duplicate here means the same log was submitted twice, not two real sales that happened to look alike, because every sale has its own TransactionID.

Impossible Quantities

What we are looking atWe want to see the rows with a quantity of zero or less before removing them, so we know what we are throwing away.
Rows where Quantity is 0 or less
ABC 123TransactionIDDATEDateABC 123StationNameABC 123ProductNameABC 123AttendantName1.2Quantity1.2UnitPrice_NGN1.2TotalAmount_NGNABC 123PaymentMethod
1TXN-2023-00166014/07/2023Independence Layout Filling StationPMS (Petrol)Chinwe Chukwu-26.6487.21-12,959.79Transfer
2TXN-2023-00191111/08/2023Independence Layout Filling StationAGO (Diesel)Chinwe Chukwu-23.71,037.47-24,588.04POS
3TXN-2023-00074425/03/2023GRA Filling StationPMS (Petrol)Kemi Balogun-55.7185.92-10,355.74Cash
4TXN-2023-00051301/03/2023Ikeja Filling StationPMS (Petrol)Unmanned-6.5185.06-1,202.89POS
5TXN-2023-00148622/06/2023Sabon Gari Filling StationPMS (Petrol)Ifeanyi Suleiman-9.6502.6-4,824.96POS
6TXN-2023-00251719/10/2023Independence Layout Filling StationGreaseUnmanned-41,204.57-4,818.28Cash
9 COLUMNS, 18 ROWS · first 6 shown

Nobody sells minus 26 litres. These are refunds or typing slips, and a sales report leaves them out. Write the number removed in your notes, because the Managing Director may ask what happened to them.

Picture This

Picture the three piles on the desk: undated to the manager, copies in the bin, refunds kept apart.

6. The Whole Recipe

Here is every step, in order, with the rows left after each one. Your Applied Steps list should read the same, and every row count should match.

What we are checkingWe want to see the complete Applied Steps list for Sales_2023 and the row count after each step.
Applied Steps: Sales_2023
⚙Navigation (Sales_2023) + Promoted Headers3,189 rows
⚙Changed Type with Locale3,189 rows
⚙Trimmed Text3,189 rows
⚙Capitalized Each Word3,189 rows
⚙Replaced Values (GRA, PMS, AGO, DPK, POS)3,189 rows
⚙Replaced Value (null to Unmanned)3,189 rows
⚙Filtered Rows (Date is not blank)3,181 rows (-8)
⚙Removed Duplicates3,134 rows (-47)
⚙Filtered Rows (Quantity > 0)3,116 rows (-18)
What we are checkingWe want to see the first rows of the finished, clean Sales_2023.
Sales_2023, clean
ABCTransactionIDDATEDateABCStationNameABCProductNameABCAttendantName1.2Quantity1.2UnitPrice_NGN1.2TotalAmount_NGNABCPaymentMethod
1TXN-2023-00038313/02/2023Bodija Filling StationPMS (Petrol)Amina Nwosu9.7187.41,817.78Cash
2TXN-2023-00246813/10/2023Bodija Filling StationEngine OilSegun Adeyemi23,402.876,805.74Cash
3TXN-2023-00216110/09/2023Bodija Filling StationPMS (Petrol)Bisi Chukwu39.7612.6124,320.62POS
4TXN-2023-00278920/11/2023GRA Filling StationPMS (Petrol)Kemi Balogun41638.4226,175.22Cash
5TXN-2023-00110305/05/2023Wuse Filling StationPMS (Petrol)Halima Umeh36.1179.686,486.45Cash
6TXN-2023-00114209/05/2023Independence Layout Filling StationGreaseChinwe Chukwu31,202.43,607.2POS
7TXN-2023-00213907/09/2023Bodija Filling StationPMS (Petrol)Segun Adeyemi44.5629.9328,031.88POS
8TXN-2023-00310127/12/2023Sabon Gari Filling StationGreaseIfeanyi Suleiman31,215.033,645.09Cash
9 COLUMNS, 3,116 ROWS · first 8 shown
Replace Values Shows Five Steps, Not One

In Power BI each Replace Values is its own step, so your list will show "Replaced Value" five times, then "Replaced Value1", "Replaced Value2" and so on. That is fine. The recipe above groups them on one line to keep it short.

Do This Now

  1. Turn on column quality, distribution and profile, based on the entire data set.
  2. Delete Power BI's Changed Type step and set every type yourself, Date with English (United Kingdom).
  3. Trim and Capitalize Each Word on the four name columns.
  4. Add the five Replace Values steps for GRA, PMS, AGO, DPK and POS.
  5. Replace null in AttendantName with Unmanned.
  6. Remove blank dates, duplicates and quantities of zero or less.
  7. Check you have 3,116 rows, and save.

Checkpoint

Q1. Why set the Date type with a locale instead of just choosing Date?

Because day-first dates are read with the laptop's region by default. With United States rules, 326 dates would be silently wrong. English (United Kingdom) reads them correctly.

Q2. Trim fixed the spaces. Why was Capitalize Each Word still needed?

Trim only removes spaces at the ends. It does nothing about "WUSE" against "Wuse".

Q3. Why do GRA, PMS, AGO, DPK and POS need Replace Values afterwards?

They are abbreviations. Capitalize Each Word turns them into Gra, Pms, Ago, Dpk and Pos, which no longer match the master sheets.

Q4. Why replace empty attendants with Unmanned instead of removing the rows?

Because they are real sales from unmanned pumps. Removing them would make revenue too low.

Tick Before You Move On

  • ☐ Date has 0% errors and was read with English (United Kingdom)
  • ☐ StationName has 7 values, ProductName 5, PaymentMethod 3, AttendantName 18 with Unmanned
  • ☐ GRA, PMS, AGO, DPK and POS are in capitals
  • ☐ Blank dates, duplicates and zero or negative quantities are gone
  • ☐ Sales_2023 has 3,116 rows

Quick Recap

The Power Query Editor records every change as a step that runs again on refresh. Column profiling shows the problems before you fix them. Set types yourself; read dates with the locale they were written in. Trim, then Capitalize Each Word, then Replace Values for the abbreviations. Replace null with a word when the empty cell means something; remove rows only when they are not real sales.

Final Scenario

Alhaji Musa Bello's accountant says the June 2023 figures look far too low compared with his own.

You open Applied Steps and show him the Date step, set to English (United Kingdom). Without it, 326 sales would have moved to the wrong month and June would have lost some of its days to May. He goes back and checks his own spreadsheet instead.

A clean query is one you can defend, step by step.

Next, Day 3: transforming data: custom and conditional columns, dates broken into parts, Split Column, Group By and Unpivot.

Learn this with a real instructor

Free lessons take you a long way on your own. The full programmes add live classes, assignments, Skill Points and a certificate — built for African students.