The request

From Chloe Gutierrez, Account Executive
Your goal
Merge the Discounts query on customer_code and expand its discount column. Customers who aren't on the list get null: replace those nulls with 0. Then add total_after_discount = line_total × (1 − discount).
- Show exactly
order_idorder_datecustomer_codeproductline_totaldiscounttotal_after_discountnot done yet - 25 rowsnot done yet
Your sheet
| order_id | order_date | customer_code | product | line_total | |
|---|---|---|---|---|---|
| 1 | 10810 | 2025-09-02 | C01335 | Vale Enamel Bowl Set | 11.99 |
| 2 | 10810 | 2025-09-02 | C01335 | Spruce Wool Duvet Cover | 267.96 |
| 3 | 10810 | 2025-09-02 | C01335 | Sable Concrete Adirondack Chair | 101.98 |
| 4 | 10816 | 2025-09-03 | C00528 | Nantucket Brass Wall Mirror | 53.97 |
| 5 | 10840 | 2025-09-04 | C01355 | Sable Linen Table Lamp | 92.99 |
| 6 | 10840 | 2025-09-04 | C01355 | Fairhaven Stoneware Cutting Board | 425.94 |
| 7 | 10849 | 2025-09-06 | C00012 | Bramble Ceramic Floor Lamp | 31.99 |
| 8 | 10849 | 2025-09-06 | C00012 | Birch Brass Floor Mirror | 167.92 |
| 9 | 10849 | 2025-09-06 | C00012 | Thatcher Oak Candle | 35.98 |
| 10 | 10849 | 2025-09-06 | C00012 | Harbor Wool Knit Throw | 231.92 |
| 11 | 10855 | 2025-09-07 | C01334 | Vale Enamel Bowl Set | 11.99 |
| 12 | 10855 | 2025-09-07 | C01334 | Harbor Wool Knit Throw | 463.84 |
| 13 | 10855 | 2025-09-07 | C01334 | Pine Cotton Area Rug | 1112 |
| 14 | 10858 | 2025-09-07 | C00026 | Harbor Wool Knit Throw | 86.97 |
| 15 | 10858 | 2025-09-07 | C00026 | Sable Concrete Adirondack Chair | 50.99 |
| 16 | 10858 | 2025-09-07 | C00026 | Dune Black Metal Floor Lamp | 207.96 |
| 17 | 10858 | 2025-09-07 | C00026 | Delancey Black Metal Wall Sconce | 109.98 |
| 18 | 10859 | 2025-09-07 | C01404 | Willow Acacia Knife Block | 107.98 |
| 19 | 10859 | 2025-09-07 | C01404 | Bramble Percale Quilt | 417 |
| 20 | 10859 | 2025-09-07 | C01404 | Rowan Ceramic Chandelier | 1134 |
| 21 | 10859 | 2025-09-07 | C01404 | Delancey Brass Vase | 79.96 |
| 22 | 10885 | 2025-09-09 | C00607 | Cove Wool Lumbar Pillow | 105.98 |
| 23 | 10885 | 2025-09-09 | C00607 | Vale Enamel Bowl Set | 23.98 |
| 24 | 10885 | 2025-09-09 | C00607 | Cedar Cast Iron Tumbler Set | 159.98 |
| 25 | 10885 | 2025-09-09 | C00607 | Bramble Percale Quilt | 417 |
Loading the editor…
Reference solution
Mote checks your result
Press Check. Each row of the result that matches becomes a firefly in your lantern.
What Chloe gets, and why
The lesson
In a worksheet you bring a value across from another table with XLOOKUP or VLOOKUP, one
formula per row. Power Query does the same job for the whole table at once with Merge
Queries. Chloe’s discount list is a second query; the order lines are the first. Merge
matches them on the customer code.
Two queries, one key
The order lines have 25 rows for 8 business customers. The Discounts query has 6 rows:
| customer_code | discount |
|---|---|
| C01335 | 0.10 |
| C01355 | 0.05 |
| C00012 | 0.10 |
| C01404 | 0.05 |
| C00288 | 0.10 |
| C00534 | 0.05 |
Four of these customers ordered in Sept 1–10. C00288 and C00534 are on the list but did not
order, which is normal: a lookup table can hold keys you won’t need. Four customers who did order
(C00528, C01334, C00026, C00607) have no contract.
Merge queries: Discounts on customer_code, expand discount
In Excel: Home → Merge Queries, pick Discounts in the second drop-down, click
customer_code in both tables, keep Join Kind: Left Outer (all from first, matching from
second), OK. Power Query adds a column full of Table values; click the expand icon on its
header, tick discount, untick “Use original column name as prefix”, OK.
Left outer: every line stays
A left outer join keeps every row of the first query. When a key has no match, the new columns
are null, Power Query’s empty value. That is the same situation as an XLOOKUP returning
#N/A, except that null does not shout. Here 12 of the 25 lines come back with a null discount.
The match is exact and case-sensitive: c01335 would not find C01335, and a code with a
trailing space would not either. When a merge finds fewer matches than you expect, check the keys
with Trim and Uppercase steps on both sides. The Merge dialog helps: at the bottom it says how many
rows matched (“The selection matches 13 of 25 rows”).
Null is not zero
Replace values: discount null with 0
In M, arithmetic with null gives null: 100 * (1 - null) is null, not 100. So before the total,
turn “no contract” into an explicit 0. In Excel: select the discount column, Transform →
Replace Values, Value To Find null, Replace With 0.
Add column: total_after_discount = [line_total] * (1 - [discount])
On the first line, C01335’s Vale Enamel Bowl Set: 11.99 × (1 − 0.10) = 10.79. On order 10816, C00528 has no contract, so the line keeps its 53.97.
The M behind the steps
#"Merged Queries" = Table.NestedJoin(Source, {"customer_code"}, Discounts, {"customer_code"},
"Discounts", JoinKind.LeftOuter),
#"Expanded Discounts" = Table.ExpandTableColumn(#"Merged Queries", "Discounts", {"discount"}, {"discount"}),
#"Replaced Value" = Table.ReplaceValue(#"Expanded Discounts", null, 0, Replacer.ReplaceValue, {"discount"}),
#"Added Custom" = Table.AddColumn(#"Replaced Value", "total_after_discount", each [line_total] * (1 - [discount]))
A merge is two steps in real Excel, the join and the expand. This practice editor folds them into one line.
Common mistakes
- Skipping the null replacement. 12 lines get a null total, and every sum built on them is too low.
- Choosing Inner join. It keeps only the 13 lines with a contract and silently drops the rest of the orders.
- Duplicate keys in the lookup table. If a customer appeared twice in Discounts, Power Query would repeat that customer’s order lines once per match. (This practice editor takes the first match; real Excel duplicates rows.) Remove duplicates on the key in the lookup query first.
- Typing the discount as 10 instead of 0.10.
1 - 10is −9. Know whether a rate is a fraction or a percentage before you multiply.
Lantern lit!
Practised: power querymerge queriesleft outer joinreplace valuesnull valuescustom column
- Solved
- No hints
- First run
