Sub topic 3
Append or merge: choosing the right operation
This chapter assumes you can load tables into the Power Query Editor from Data > Get & Transform, and that you know what column data types are. It also assumes you have a general idea of what a lookup or join does. Here you will learn to look at two tables and decide which operation applies before you click anything.
The two operations in one sentence each
- Append stacks the rows of one table under the rows of another. The result has more rows. It has the same columns, or the union of the columns if the tables differ.
- Merge matches rows between two tables on one or more key columns and brings in extra columns. The result has the rows of one table (usually) and more columns.
Both live on the Home tab of the Power Query Editor, in the Combine group. The buttons are Merge Queries, Merge Queries as New, Append Queries, and Append Queries as New. The "as New" variants leave both source queries untouched and create a third query with the result. The plain variants add a step to the query you have selected, which changes that query.
The deciding question
Ask what the relationship between the two tables is.
- Same kind of thing, different batches. Sales for 2023 and sales for 2024. Each row in either table is an order. You want one list of all orders. Use append.
- Different kinds of things, linked by an ID. Orders and Customers. An order row says which customer placed it, and the customer row says where that customer lives. You want each order to carry the customer's region. Use merge.
A quick test is to imagine the two tables side by side on a desk. If you would slide one under the other to make one long table, append. If you would slide one next to the other and line up rows by an ID, merge.
What each operation does to the shape of the data
| Property | Append | Merge |
|---|---|---|
| Row count of result | Rows in A plus rows in B | Depends on join kind and key uniqueness |
| Column count of result | Union of columns from both tables | Columns of the first table plus the ones you expand |
| Needs a key | No | Yes |
| Matches columns by | Column name | Key column values |
| Can create nulls | Yes, where a column exists in only one table | Yes, where a row has no match |
| Can duplicate rows | No | Yes, if the key repeats in the second table |
| Order matters | Row order only | Which table is first decides which rows are kept by default |
The row count rule is the most useful check. After an append, the output must have exactly the sum of the input rows. After a merge, there is no fixed rule, so you must reason about it. Later chapters cover the verification steps in detail.
A runnable comparison
The following queries use inline tables, so you can paste each into a blank query in the Advanced Editor and run it without any source data.
First, an append. Both tables describe orders.
let
Sales_2023 = #table(
type table [OrderID = Int64.Type, Amount = number],
{{1, 100}, {2, 250}}
),
Sales_2024 = #table(
type table [OrderID = Int64.Type, Amount = number],
{{3, 80}}
),
Combined = Table.Combine({Sales_2023, Sales_2024})
in
CombinedThe result has three rows and two columns. Rows 1 and 2 come first, then row 3.
Now a merge. The tables describe different things, and CustomerID links them.
let
Orders = #table(
type table [OrderID = Int64.Type, CustomerID = text],
{{1, "A1"}, {2, "B2"}, {3, "Z9"}}
),
Customers = #table(
type table [CustomerID = text, Region = text],
{{"A1", "East"}, {"B2", "West"}}
),
Merged = Table.NestedJoin(
Orders, {"CustomerID"},
Customers, {"CustomerID"},
"Customers", JoinKind.LeftOuter
),
Expanded = Table.ExpandTableColumn(Merged, "Customers", {"Region"}, {"Region"})
in
ExpandedThe result has three rows and three columns. Order 3 has null in Region because customer Z9 does not exist in Customers. The row count stayed at three because the left table decides which rows survive and each customer ID appears once.
What goes wrong when you pick the wrong one
Appending when you should merge
If you append Orders and Customers, Power Query does not complain. It produces a table with columns OrderID, CustomerID, and Region. The order rows have null in Region, and the customer rows have null in OrderID. The data forms a staircase of nulls. No row has both an order and a region, so the information you wanted is not connected.
The symptom is a result where every row is half empty. If you see that after an append, you probably needed a merge.
Merging when you should append
If you merge Sales_2023 and Sales_2024 on OrderID, you get only the orders that appear in both, or all 2023 orders with null columns for those not in 2024. Neither is the combined list you wanted. The symptom is a result that has duplicated columns such as Amount and Amount.1, or a row count lower than expected.
Using merge to look up one value, then appending the lookup
A frequent beginner pattern is to append many tables and then merge the combined result against a lookup. That order is usually right, because the lookup then runs once. The reverse, merging each small table separately and appending afterward, repeats the same lookup many times and is harder to maintain.
Edge cases to watch for
Append does not remove duplicates
If the same order exists in both Sales_2023 and Sales_2024, it will appear twice in the appended result. Append only stacks. If overlap is possible, remove duplicates in a later step with Home > Remove Rows > Remove Duplicates, selecting the key columns first.
Append matches columns by name, not position
If one table has Amount and the other has Total, they become two separate columns with nulls filling the gaps. Rename columns to match before appending. Names are case sensitive, so amount and Amount are different columns. The next chapters cover this in more detail.
Merge keeps only one copy of each first-table row, until the second table repeats a key
If Customers listed customer A1 twice, expanding the merged column would turn order 1 into two rows. Merge does not change the row count by itself when you leave the merged column unexpanded, but expanding a column with several matching rows multiplies them. This is why you decide between "expand" and "aggregate" after the merge.
Data types must agree for merge keys
A CustomerID stored as number in one table and text in the other will not match, even when the values look identical. Append is more forgiving. If the same column has different types in the two tables, Power Query combines them and the result column takes type any, so you should set the type explicitly afterward.
Both operations can be needed
Real tasks often use both. Monthly sales files with identical layout get appended into one table. That table is then merged with a product list to add category names. The append comes first because the merge should run once on the full set. A later chapter builds this pipeline step by step.
A short checklist
- Write down what one row means in each table. If the meaning is the same, think append.
- If the meanings differ, find the column that links them. If one exists, think merge.
- If you choose append, confirm that column names and types agree.
- If you choose merge, confirm that the key columns have the same type and that you know which table may repeat key values.
- Predict the result's row count before you look at it, then compare.
Exercise
You have a table Invoices with columns InvoiceID, CustomerID, and Total, and a table Customers with columns CustomerID, Name, and Country. You need a report that shows each invoice with the customer's country. Should you append or merge, and what would you see if you chose the other one?
Show answer
Merge, with Invoices as the first table and Customers as the second, matched on CustomerID, then expand Country. If you appended instead, the result would have columns InvoiceID, CustomerID, Total, Name, and Country. Invoice rows would have null in Name and Country, and customer rows would have null in InvoiceID and Total, so no invoice would carry a country.
Exercise
You append Sales_2023 (1,200 rows) and Sales_2024 (1,500 rows) and get 2,640 rows. What does this tell you, and what should you check?
Show answer
An append should return exactly 2,700 rows, so something is off. Possible causes are a later step that removed rows, such as Remove Duplicates, a filter, or an error removal, or a different source than expected, such as a table that was filtered or had a header problem. Review the applied steps after the append and compare row counts at each step.