Sub topic 3
Expanding or Aggregating the Merged Column
Assume you know the Power Query Editor, table data types, and the difference between an append and a merge. A merge adds a nested table column containing matching rows from another query.
Expand or aggregate
After a merge, select the expand button on the new column. Choose fields such as Name and Region. Expansion adds those fields to the main table. If one row matches several rows, expansion duplicates the main row.
Use aggregation when you need one result per original row, such as a customer total.
let
Source = Table.NestedJoin(
Customers, {"CustomerID"},
Orders, {"CustomerID"},
"Orders", JoinKind.LeftOuter
),
Totals = Table.AggregateTableColumn(
Source, "Orders",
{{"Amount", List.Sum, "Total Amount"}}
)
in
TotalsVerify missing and duplicated rows
Check the merge before trusting the output.
| Check | What it reveals |
|---|---|
| Unmatched keys | Missing lookup records |
| Row count after expansion | Duplicated rows from one-to-many matches |
| Duplicate keys in the lookup | A likely source of unexpected multiplication |
A left anti join returns rows from the first query with no match. Use it to find missing customers or products.
Fuzzy matching
Fuzzy matching compares similar text instead of requiring exact equality. It can match values such as Northwind Ltd and Northwind Limited, but it can also create false matches. Review results and use a threshold appropriate to the data.
Append, then merge
A common pipeline appends monthly sales queries first. It then merges the combined sales table with a customer lookup. This keeps the transformation logic centralized and avoids repeating the merge for every month.
Read the M code
Append uses Table.Combine, which stacks rows:
let
Source = Table.Combine({Sales_2023, Sales_2024})
in
SourceMerge uses Table.NestedJoin; Table.ExpandTableColumn then adds selected fields. The join kind controls which rows remain.
Refresh and performance
Power Query reruns every step during refresh. Filter unused columns and rows before a merge, keep key data types consistent, and avoid expanding fields you do not need. Aggregation can use less memory than expanding a large one-to-many relationship.
Exercise
Which operation should you use to calculate one order total per customer without duplicating customer rows?
Show answer
Merge the customers with orders, then aggregate the nested Amount column with List.Sum.