Stack and match tables with Append and Merge
Power Query basics9 minPremium
Builds on Why Power Query: record a cleanup once, repeat it every month and Look up a price with XLOOKUP.
A support team lead in Lisbon gets one list of tickets per month and a separate list of agents with their teams. She wants one list of every ticket, with the agent's team beside each one.
How it works
Append Queries, on the Home tab, stacks the rows of other queries under the rows of this one. It matches the columns by name, so their order doesn't matter, and a column that only one table has comes through with null in the other tables' rows. Choose Two tables, or Three or more tables to add several at once.
Merge Queries, beside it, is Power Query's lookup. Pick the second table, click the column the two share in each, such as AgentID, and pick the Join Kind:
- Left Outer keeps every row of the first table and fills in what matches from the second.
- Inner keeps only the rows that match in both, so a ticket whose agent isn't on the list disappears.
The merge adds a column that holds a small table for each row, the matching rows of the second table. Click the expand button in its heading, tick the columns to bring over, and clear Use original column name as prefix to keep their plain names. A key that matches twice brings two rows, so merge with a table that lists each key once.
Example
Appending stacks the rows, matching the columns by name:
Merging brings the team over from the agents' list, matched on AgentID:
Common mistakes
- Inner where every row should stay. A ticket whose agent joined after the agents' list was made disappears. Use Left Outer, and look for the rows that show null.
- Merging on columns of different types, such as a number in one table and text in the other. The rows don't match. Set both columns to the same type first.
- Leaving the prefix on. The new columns come out as Agents.Team. Clear Use original column name as prefix in the expand list.
- Appending tables whose headings differ, such as Qty and Quantity. Each becomes a column of its own, half empty. Rename one first.
In short
- Append Queries stacks rows and matches columns by name.
- Merge Queries matches rows on a shared column, and the expand button brings the columns over.
- Left Outer keeps every row of the first table, and Inner only those that match.
Practice
Premium4 exercises: 3 queries and 1 quiz question.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in