Sub topic 4
Appending Two Queries
This chapter covers the Append Queries command: what it does, how to run it, what it generates, and the errors people hit most often. It assumes you can load a table into the Power Query Editor with Data > Get & Transform, you know the basic column data types (text, number, date), and you have already decided that your task needs stacked rows rather than extra columns. If that decision is still open, review the chapter on choosing between append and merge first.
What an append does
An append takes two tables and returns one table. The rows of the first table come first, and the rows of the second table follow directly below them. No rows are matched, combined, or removed. If the first table has 1,200 rows and the second has 800, the result has 2,000 rows.
Typical uses are monthly or yearly exports that share a layout, such as Sales_2023 and Sales_2024. Both tables describe the same kind of thing, so stacking them gives you one table to analyze.
Two points to keep in mind:
- An append never checks for duplicates. If the same row exists in both tables, it appears twice in the result.
- The order of the two queries matters for row order, and, as the next chapter explains, it also matters for column order.
Prepare the two queries
Before you append, load each source as its own query. A common setup is to load each table with Data > Get & Transform and, in the Import dialog, choose Only Create Connection. That creates a connection-only query. It exists in the Power Query Editor but does not put a table on a worksheet. This is usually what you want for inputs, because the useful output is the combined table, not the two pieces.
In this chapter the two inputs are Sales_2023 and Sales_2024. Each has the columns OrderID, Date, Product, and Amount.
Run the append in the editor
- In Excel, open Data > Get Data > Combine Queries > Append. If you are already in the Power Query Editor, use Home > Append Queries.
- In the Append dialog, leave Two tables selected.
- Choose
Sales_2023as the First table. - Choose
Sales_2024as the Second table to append. - Select OK.
The editor opens a new query, named Append1 by default, and shows the stacked rows. Its Applied Steps pane contains one step named Source. Rename the query to something meaningful, such as Sales_All, by editing the name in the Query Settings pane.
Home > Append Queries has a second option, Append Queries as New. The difference is important:
| Command | Effect on the first query | Result |
|---|---|---|
| Append Queries | Adds an Appended Query step to the query you currently have selected. | The original query now contains both tables. |
| Append Queries as New | Leaves both inputs unchanged. | A new query holds the stacked result. |
For most workflows, use Append Queries as New. It keeps Sales_2023 and Sales_2024 intact, so you can still use them elsewhere, and it makes the pipeline easier to read.
The M code behind the command
Every step in the editor is stored as M code, the Power Query formula language. You can see it by opening View > Advanced Editor. For the append above, the query is:
let
Source = Table.Combine({Sales_2023, Sales_2024})
in
SourceTable.Combine takes a list of tables, written in braces, and returns one table. The list order is the stacking order. A few things follow from this:
- The names inside the braces are other queries in the same workbook. They are references, not text, so they have no quotes.
- To add a third table you add another name to the list. The chapter on appending three or more queries returns to this.
- If you rename
Sales_2023in the Queries pane, the editor updates the reference for you. If you edit the code by hand to refer to a name that does not exist, you get an error saying the name wasn't recognized.
What happens to columns
Table.Combine matches columns by name, not by position. If both tables have Amount, their values land in one Amount column, even if the columns are in different positions in each source.
When a column exists in only one of the tables, the result still includes it. The rows that came from the other table get null in that column. Suppose Sales_2024 has an extra Channel column:
| OrderID | Product | Amount | Channel |
|---|---|---|---|
| 1001 | Widget | 25 | null |
| 1002 | Gadget | 40 | null |
| 2001 | Widget | 30 | Online |
The first two rows come from Sales_2023, which has no Channel, so those cells are null. The third row comes from Sales_2024.
Because matching is by name, a small difference in a header produces two columns instead of one. Amount and Amount (with a trailing space) are different names. So are Amount and amount, since column names are case-sensitive. The result then has both columns, each half filled with null. The next chapter covers how to detect and repair this.
Data types in the result
Each column in the result has one data type. When the two sources agree, the type carries through. When they disagree, for example OrderID is a whole number in one table and text in the other, Power Query cannot give the column a single specific type, and it falls back to Any. A column of type Any may show a mix of left-aligned text and right-aligned numbers.
You should set the type explicitly as a later step. In the editor, select the column, then use Transform > Data Type. If some text values cannot convert to the target type, those cells become Error values, and you will see them when you set the type. To investigate, right-click the column and choose Keep Errors, or look at the error message in the cell preview.
A related issue is a number stored as text in only one source. Converting the column to a whole number or decimal number fixes it, as long as the text values contain only digits (and a decimal separator that matches your locale).
Common errors and how to read them
| Symptom | Likely cause | Fix |
|---|---|---|
| The result has two similar columns, each partly `null` | Headers differ in spelling, spacing, or case | Rename the columns in one source so they match exactly, then refresh |
| A column shows the Any type | The two sources use different types for that column | Set the type in the appended query, or fix it in each source |
| Rows look doubled | Overlapping periods exist in both sources | Filter the sources, or use Remove Duplicates on the key columns after the append |
| `Expression.Error: The name 'Sales_2023' wasn't recognized` | The query was renamed or deleted, and the code was edited by hand | Correct the name in the Advanced Editor |
| The headers appear as data rows in the middle of the result | One source did not promote its first row to headers | Apply Use First Row as Headers in that source query |
The last row of that table deserves attention. If a source file has its header in the first row of data and the query never promoted it, that row is carried into the result as an ordinary row, where it looks like OrderID, Date, and so on. Always inspect the top and bottom of each source before you append.
Check the result
After any append, do a quick check. The row count of the result should equal the sum of the row counts of the two inputs.
- Select each input query and read the row count in the status bar at the bottom of the editor, for example "1200 ROWS". If the bar shows only column profiling, enable View > Column profile based on entire data set so the count covers all rows rather than the first 1,000.
- Add the two counts.
- Select the appended query and compare.
If the numbers differ, something other than the append changed the rows, such as a filter step you added after Source. A true Table.Combine of two tables always returns the exact sum.
Where the result is loaded
The appended query is the one you normally load. Choose Home > Close & Load To and pick Table to put it on a worksheet, or Only Create Connection if another query, such as a merge, will use it next. Loading it to the Data Model is also an option when you plan to use it in a PivotTable. The inputs can stay as connection-only queries, so the workbook holds one visible table instead of three.
Refresh behavior
When you refresh, Power Query rereads both sources and rebuilds the stack. If someone adds rows to Sales_2024 in its source file, the appended query picks them up with no change to the steps. If a source adds a new column, the append includes it, with null in the other table's rows. If a source removes or renames a column that a later step refers to, the refresh fails with a column-not-found error, so keep any steps after the append aware of which column names they rely on.
Exercise
You append Orders_East (columns OrderID, Amount, Region) and Orders_West (columns OrderID, amount, Region). Orders_East has 300 rows and Orders_West has 200. The result has 500 rows but four columns, and the Amount columns are each half null. What happened, and how do you fix it?
Show answer
Column names are matched exactly, including case. Amount and amount are different names, so the append kept both and filled the missing side with null. The row count is correct because append never drops rows. Rename amount to Amount in Orders_West (or in a step before the append), then refresh. The result will have three columns and 500 rows with no nulls in Amount.
Exercise
Write the M expression that stacks Sales_2023 first and Sales_2024 second, and state what row count you should expect if they hold 1,200 and 800 rows.
Show answer
Table.Combine({Sales_2023, Sales_2024}). The expected result has 2,000 rows, because append returns the sum of the input row counts.