Courses Learn Blog Contact
Get Started →
Lesson 7

Day 5: Appending and Merging Queries

Stacking 2023 and 2024 into one table, and looking up product and attendant details by ID.

Webbo3 Power BI Cohort 1 9 min read Free

Webbo3 Power BI · Cohort 1 · Day 5 of 16

Day 5: Appending and Merging Queries

Two ways of joining tables: stacking more rows underneath, or bringing more columns alongside.

By the end of today you can

  • Say the difference between Append and Merge in one sentence
  • Append the clean 2023 and 2024 queries into one Sales table
  • Merge Sales with Station_Master and Product_Master on the cleaned names
  • Merge Station_Targets into Station_Master on StationID, and sense-check what it says
  • Choose the right join kind, and use Left Anti to find rows that do not match

Week 1 ends with one table. Two clean years, joined to what Webbo Oil knows about each station and each product.

Open your file with Sales_2023_Clean and Sales_2024_Clean (Day 4 and Assignment 1) and the four master sheets.

1. Append and Merge: The Difference

Definition

Append stacks one table underneath another: same columns, more rows. Merge puts columns from another table alongside, by matching a column the two tables share: same rows, more columns.

Real-Life Example

Append is stapling February's register under January's: the columns are the same, there are just more names. Merge is looking up each student's home address in the admissions file and writing it next to their name.

AppendMerge
AddsRowsColumns
NeedsThe same column namesA column both tables share
Webbo Oil2023 and 2024 sales into one tableCity and Region onto each sale
Picture This

Picture the stapler for Append, and the address book for Merge.

2. Append Queries

Definition

Append Queries as New makes a new query from two or more queries stacked in order. Columns are matched by name, so both clean years must have exactly the same column names, spelled the same way.

Types

ButtonWhat it doesUse it when
Append QueriesAdds rows onto the query you are onRarely: it changes a query others may use
Append Queries as NewMakes a separate, new queryAlmost always

Click path

1.Home › Append Queries › Append Queries as New
2.Two tables › First: Sales_2023_Clean › Second: Sales_2024_Clean › OK › Rename it Sales
3.Right-click Sales_2023_Clean and Sales_2024_Clean › Untick Enable load
What we are checkingWe want the row count of each year and of the appended table, which must be exactly the two added together.
Row counts
⚙Sales_2023_Clean3,116 rows
⚙Sales_2024_Clean3,065 rows (-51)
⚙Sales (appended)6,181 rows (+3,116)

Untick Enable load on the two yearly queries: they are ingredients now, and loading all three would put every sale in the model twice.

What we are checkingWe want to see the appended Sales table, with a 2024 sale directly below the last 2023 one.
Sales, around the join
ABCTransactionIDDATEDateABCStationNameABCProductNameABCAttendantName1.2Quantity1.2UnitPrice_NGN1.2TotalAmount_NGNABCPaymentMethod
1TXN-2023-00156203/07/2023GRA Filling StationPMS (Petrol)Halima Chukwu45.2479.8321,688.32POS
2TXN-2023-00085607/04/2023Ikeja Filling StationAGO (Diesel)Funke Yakubu45.4743.133,736.74Cash
3TXN-2024-00238613/10/2024Wuse Filling StationEngine OilTunde Danjuma14,510.434,510.43Transfer
4TXN-2024-00218319/09/2024Independence Layout Filling StationPMS (Petrol)Ngozi Ogunleye14.6892.2213,026.41POS
5TXN-2024-00045221/02/2024Independence Layout Filling StationDPK (Kerosene)Chinwe Chukwu39.21,137.2344,579.42POS
9 COLUMNS, 6,181 ROWS · first 8 shown
If Append Adds Columns

A new column full of null at the end of the table means one year has a column the other lacks, often a spelling difference such as "Totalamount_NGN". Rename it to match and the extra column disappears.

3. Merge Queries

Definition

Merge Queries looks up each row's value in another table and brings matching columns across. You choose the column to match in each table, the join kind, and then which columns to expand.

Real-Life Example

The address book again: you look up "Wuse Filling Station", find its row, and copy "Abuja" and "North Central" next to every Wuse sale.

Merge on Names Only After They Are Clean

Webbo Oil's sales sheets have no StationID or ProductID: they only hold names. A merge matches letter for letter, including capitals and spaces. That is why Day 2 had to make every name identical to the master sheets. The next section proves it.

Click path

1.Sales query › Home › Merge Queries › Merge Queries
2.Top: Sales, click StationName › Bottom: Station_Master, click StationName › Join Kind: Left Outer › OK
3.Expand icon on the new column › Tick City and Region only › Untick "Use original column name as prefix" › OK

Power Query reports how many rows matched at the bottom of the Merge window. You want "The selection matches 6,181 of 6,181 rows". Anything less means a name that is not spelled as on the master sheet.

Now the products

1.Home › Merge Queries › Top: Sales, ProductName › Bottom: Product_Master, ProductName › Left Outer › OK › Expand: Category
What we are checkingWe want to see the merged Sales table: every sale now carries its station's city and region and its product's category.
Sales after two merges
ABCTransactionIDDATEDateABCStationNameABCCityABCRegionABCProductNameABCCategory1.2TotalAmount_NGN
1TXN-2023-00038313/02/2023Bodija Filling StationIbadanSouth WestPMS (Petrol)Fuel1,817.78
2TXN-2023-00246813/10/2023Bodija Filling StationIbadanSouth WestEngine OilLubricant6,805.74
3TXN-2023-00216110/09/2023Bodija Filling StationIbadanSouth WestPMS (Petrol)Fuel24,320.62
4TXN-2023-00278920/11/2023GRA Filling StationPort HarcourtSouth SouthPMS (Petrol)Fuel26,175.22
5TXN-2023-00110305/05/2023Wuse Filling StationAbujaNorth CentralPMS (Petrol)Fuel6,486.45
6TXN-2023-00114209/05/2023Independence Layout Filling StationEnuguSouth EastGreaseLubricant3,607.2
7TXN-2023-00213907/09/2023Bodija Filling StationIbadanSouth WestPMS (Petrol)Fuel28,031.88
8TXN-2023-00310127/12/2023Sabon Gari Filling StationKanoNorth WestGreaseLubricant3,645.09
8 COLUMNS, 6,181 ROWS · first 8 shown
What this showsWe want to use a merged column straight away: revenue by product category across both years, the first look at whether fuel or lubricants carries the business.
Revenue by Category
CategoryRevenueShare
Fuel₦139,263,15595.5%
Lubricant₦6,591,0714.5%
Total₦145,854,226100.0%
Picture This

Picture the address book open on the desk: every sale looks up its station and copies the city across.

4. The Targets: Merge on an ID, Then Ask if It Makes Sense

Definition

Station_Targets holds one target per station. It has a StationID, and so does Station_Master, so the two can be merged on an ID, which is the safest kind of key: typed by a system, never by a person.

Click path

1.Station_Master query › Home › Merge Queries › Top: StationID › Bottom: Station_Targets, StationID › Left Outer › OK › Expand: MonthlyRevenueTarget_NGN

The Sense Check

Before any number goes into a report, ask whether it could possibly be true. The column is called MonthlyRevenueTarget_NGN. Put it beside what each station really earns in an average month:

What we are checkingWe want each station's real average revenue per month next to the target the sheet calls monthly, and what the share would be if the target were really for a year.
Sense check: the targets
StationReal revenue per monthTarget (sheet says monthly)If monthlyIf yearly
Ikeja Filling Station₦852,305₦18,000,0004.7%57%
Lekki Filling Station₦843,639₦15,000,0005.6%67%
Wuse Filling Station₦857,963₦14,000,0006.1%74%
GRA Filling Station₦899,291₦20,000,0004.5%54%
Bodija Filling Station₦891,326₦9,000,0009.9%119%
Sabon Gari Filling Station₦848,467₦8,500,00010.0%120%
Independence Layout Filling Station₦884,269₦7,000,00012.6%152%

No station comes close to its "monthly" target: on average each reaches between about 4% and 13% of it, and even its best single month never reaches a quarter (the highest is 22%). That is not seven failing stations; it is a label that is wrong. Read as a yearly target, the figures make sense: some stations beat it and some fall short. Head Office confirms the targets are for a year. So you rename the column, in Power Query, where the fix is recorded as a step:

Click path

1.Double-click the MonthlyRevenueTarget_NGN header › Type AnnualRevenueTarget_NGN › Enter
Fix Labels in Power Query, Not in Your Head

If you remember "it is really yearly" but leave the column name alone, the next analyst to open the file builds a monthly comparison on it. The renamed column, and the step that renamed it, are the record of what you found.

Picture This

Picture a scale showing 200 kg for a child: you do not report it, you check the scale.

5. Join Kinds

Definition

The join kind decides which rows survive a merge: the ones in the first table, the second, both, or only the ones that do not match.

Real-Life Example

A guest list and the list of people who arrived. Do you want everyone invited, everyone who came, only those on both lists, or only the invited who did not come?

Types

Join KindKeepsUse it for
Left OuterEvery row of the first table; empty where there is no matchAdding details (the default)
InnerOnly rows that match in bothKeeping only what matches
Right OuterEvery row of the second tableRarely
Full OuterEvery row of bothComparing two lists
Left AntiRows of the first table with no matchFinding what failed to match

Left Anti: Proving Why We Cleaned First

Click path

1.Reference raw Sales_2023 (before any cleaning) › Merge Queries › Top: StationName › Bottom: Station_Master, StationName › Join Kind: Left Anti › OK
What we are checkingWe want to count the 2023 sales whose station name matches nothing on Station_Master, on the raw sheet, after Capitalize Each Word only, and after the full cleaning.
Left Anti against Station_Master
Sales_2023 at this pointRows with no matching stationOf
Raw, as typed1,8783,189
After Trim and Capitalize Each Word only4403,189
Fully cleaned03,116

On the raw sheet 59% of sales would have found no station. After Capitalize Each Word the 440 left over are all "Gra Filling Station", the one the five Replace Values steps fix. A Left Anti merge that comes back empty is the proof your cleaning worked.

Try This

Run the Left Anti merge on your own clean Sales query against Station_Master, and again against Product_Master on ProductName. Both should return 0 rows. Delete the test queries afterwards.

Do This Now

  1. Append Sales_2023_Clean and Sales_2024_Clean as a new query called Sales; untick load on the two years.
  2. Merge Station_Master into Sales on StationName: expand City and Region.
  3. Merge Product_Master into Sales on ProductName: expand Category.
  4. Merge Station_Targets into Station_Master on StationID, do the sense check, and rename the column.
  5. Run a Left Anti merge to prove every station and product matched.

Checkpoint

Q1. Append or Merge: adding 2024 sales under 2023?

Append: same columns, more rows.

Q2. Append or Merge: adding each sale's region?

Merge: same rows, more columns, matched on StationName.

Q3. Why could the station merge only work after Day 2?

A merge matches letter for letter. Until the names were trimmed, capitalised and the abbreviations fixed, most sales matched no station at all.

Q4. How did you know the target column was mislabelled?

In 24 months, no station ever reached even a quarter of its "monthly" target. Read as yearly, the figures make sense. A number that could not possibly be true is a label problem.

Tick Before You Move On

  • ☐ Sales has 6,181 rows: 3,116 plus 3,065
  • ☐ Every sale has a City, a Region and a Category
  • ☐ Station_Master has AnnualRevenueTarget_NGN, renamed from the monthly label
  • ☐ My Left Anti merges return 0 rows
  • ☐ The two yearly queries have Enable load unticked

Quick Recap

Append adds rows; Merge adds columns. Append Queries as New, then untick load on the ingredients. A merge matches letter for letter: cleaning comes first. IDs are the safest key; names work once they are clean. Sense-check every number, and fix a wrong label in Power Query.

Final Scenario

Alhaji Musa Bello glances at your first region table and says, "So the targets are monthly, and every station is failing?"

You show him the sense check: in two years no station reached even a quarter of a "monthly" target. He laughs: Head Office always sets them for the year. The column is already renamed, and the step that renamed it is in Applied Steps for the next analyst to see.

The most useful question in analysis is "could this possibly be true?"

Next, Day 6 Lab: Append and Merge together, Close & Apply, and what a data model actually is.

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.