Sub topic 4
Appending Two Queries
This chapter assumes you can load data into the Power Query Editor, know what applied steps are, and have two Excel tables with the same kind of data, such as one table per year of sales. You will stack the rows of one query under another, check the result, and read the M code the operation generates.
What append does
Append adds the rows of a second query to the end of the first. The result is one longer table. Use it when both tables describe the same kind of record, for example Sales2023 and Sales2024, each with columns such as Date, Product, and Amount.
Append does not match rows against each other. It only stacks them. If you need to add columns from another table, use a merge, which a later chapter covers.
Running the append
Both tables must already exist as queries. Connection-only queries work well here, because you only need the combined result loaded.
- In the Power Query Editor, select the query that should supply the first rows, here Sales_2023.
- On the Home tab, choose Append Queries. The menu offers Append Queries and Append Queries as New.
- Choose Two tables, then pick Sales_2024 as the second table.
- Select OK.
The choice in step 2 matters:
| Command | What happens |
|---|---|
| Append Queries | Adds an Appended Query step to the selected query and changes it |
| Append Queries as New | Creates a new query and leaves both sources unchanged |
Prefer Append Queries as New when the two source tables should stay available on their own. Name the new query something clear, such as Sales_All.
The M code
The editor writes this step for you. You can see it in the formula bar or the Advanced Editor.
let
Source = Table.Combine({Sales_2023, Sales_2024})
in
SourceTable.Combine takes a list of tables, written in curly braces, and returns one table. The order in the list is the order of the rows. Sales2023 rows come first, then Sales2024 rows. A column that exists in only one table is kept, and the rows from the other table get null in it.
Checking the result
After the append, confirm three things:
- Row count. The combined table should have as many rows as the two sources added together. If you see fewer, a source may have been filtered or may have errors.
- Column names. A misspelled column in one source, such as
AmountandAmt, produces two separate columns, each half filled withnull. - Data types. Check that each column has the type you expect, and set the type again after the append if needed.
The next chapter covers column matching and data types in detail.
Loading the result
Select Close & Load To... and choose a table, a connection only, or the Data Model. When the sources were only building blocks, load just the combined query and leave the sources as connection only.
Exercise
You have queries OrdersNorth and OrdersSouth with identical columns, and you need one table of all orders without changing either source. Which command do you use, and what M function does it generate?
Show answer
Use Append Queries as New with the two tables option. It generates a step that calls Table.Combine({OrdersNorth, OrdersSouth}) in a new query, and both source queries stay unchanged.
Exercise
Sales2023 has 1,200 rows and Sales2024 has 1,350 rows. After appending, the result has 2,550 rows, but a column named Discount is null for all 1,200 rows from 2023. What does this tell you?
Show answer
Append worked correctly because 1,200 + 1,350 = 2,550. The Discount column exists only in Sales_2024, so the 2023 rows receive null. Check whether the 2023 table uses a different name for the same column.