Sub topic 1
Where merge and append live in the Power Query Editor
This chapter shows you where the merge and append commands are in Excel, how the Power Query Editor window is laid out, and how each command appears as a step in a query. Later chapters cover the behavior of each operation in detail. Here you learn to find your way around.
Prerequisites
This chapter assumes you can do the following:
- Work with Excel tables and ranges, including naming a table in the Table Design tab.
- Use Data > Get & Transform to load data into the Power Query Editor.
- Recognize column data types such as text, number, and date.
- Explain in general terms what a lookup or a join does.
You do not need to know the M language. You will only look at it briefly at the end.
The two entry points
You can start a merge or an append from two places. Both lead to the same dialogs, but the starting context is different.
| Entry point | How to reach it | What it does to your queries |
|---|---|---|
| Excel ribbon | Data > Get Data > Combine Queries > Merge or Append | Creates a new query that holds the result. Your source queries stay unchanged. |
| Power Query Editor ribbon | Home > Combine > Merge Queries or Append Queries | Changes the current query, or creates a new one if you choose the "as New" variant. |
In the Power Query Editor, each command has two variants:
- Merge Queries and Append Queries add a step to the query that is currently selected. The result replaces that query's output.
- Merge Queries as New and Append Queries as New leave the selected query alone and create a new query for the result.
The "as New" variants are usually the safer choice while you are learning. Your source queries remain intact, and you can compare them with the combined result.
In Excel, the Combine Queries commands are only enabled when the workbook already contains at least two queries. If the menu items are grayed out, you have not yet created a second query.
A tour of the Power Query Editor
Open the editor by selecting any cell in a table and choosing Data > From Table/Range, or by choosing Data > Get Data > Launch Power Query Editor. The window has five areas that matter for combining queries.
- Ribbon. The Home tab holds the Combine group with Merge Queries and Append Queries. The Transform and Add Column tabs hold commands for cleaning the data before you combine it.
- Queries pane. This list on the left shows every query in the workbook. You select a query here to see its data and its steps. You can also right-click a query to duplicate, reference, rename, or delete it.
- Data preview. The center grid shows the output of the step you have selected. It is a preview of a sample of rows, not necessarily all of them.
- Query Settings pane. On the right, this pane holds the query name and the Applied Steps list.
- Formula bar. Above the grid, it shows the M expression for the selected step. If you do not see it, turn it on under View > Formula Bar.
Applied Steps
Every action you take in the editor becomes a named step in the Applied Steps list. A merge appears as a step called Merged Queries. An append appears as Appended Query. If you expand the merged column afterward, a further step called Expanded followed by the new column's name is added.
Selecting an earlier step shows the data as it was at that point. This is the main tool for debugging. If a merge gives odd results, click the step before it and look at the input.
You can rename, reorder, or delete steps. Be careful with deletion. Later steps often depend on earlier ones, and removing a step can produce an error such as "The column 'X' of the table wasn't found."
Source queries versus result queries
Combining queries involves at least three queries: the sources and the result. It helps to keep their roles clear.
- Source queries bring in raw tables, for example
Sales_2023andSales_2024. They should do only basic cleaning, such as fixing data types. - The result query combines the sources. In the Queries pane it can reference the sources by name.
- Intermediate queries are optional queries that sit between sources and the final output. A later chapter describes a pipeline that appends first and then merges.
A good habit is to name queries by role. Names like Sales_2023, Customers, and Sales_Combined tell you at a glance what each one is. The names you choose also appear in the dialogs and in the M code, so clear names make both easier to read.
Walkthrough: opening the Merge dialog
The following steps open the Merge dialog without completing it. They assume the workbook contains two queries named Orders and Customers.
- In Excel, choose Data > Get Data > Launch Power Query Editor.
- In the Queries pane, select
Orders. - On the Home tab, in the Combine group, choose Merge Queries as New.
- In the dialog, the top table is the query you selected. It is called the left table. Pick
Customersfrom the drop-down below it. This is the right table. - Click a column header in each table to mark it as a key. A number appears beside a selected column, showing its position in the key.
- Read the message at the bottom of the dialog. It reports how many rows from the first table match the second table.
- Click Cancel for now. You will complete a merge in a later chapter.
The order of the two tables matters. The first table is the "left" side of the join, and this decides which rows a left join keeps. If you choose the wrong query first, cancel and start again from the right one.
The Append dialog
The Append dialog has two modes, chosen with radio buttons at the top:
- Two tables. You choose a first table and a second table from drop-downs.
- Three or more tables. You add tables from a list on the left into a list on the right. You can also reorder them.
The order of tables in the Append dialog sets the order of the rows in the result and of the columns. A later chapter explains how columns line up.
Seeing the code behind the commands
Each command writes M code, and you can see it in the formula bar. With the Merged Queries step selected, the formula bar might show this:
= Table.NestedJoin(Orders, {"CustomerID"}, Customers, {"CustomerID"}, "Customers", JoinKind.LeftOuter)With an Appended Query step selected, you might see this:
= Table.Combine({Sales_2023, Sales_2024})You do not need to write this code by hand to use the dialogs. Knowing where to look is enough for now, because the code lets you confirm which tables and which join kind the dialog actually chose.
For the full query text, select Home > Advanced Editor. It shows every step in a let ... in block.
let
Source = Table.Combine({Sales_2023, Sales_2024})
in
SourceCommon mistakes with where things live
- Editing the source query by accident. Choosing Merge Queries instead of Merge Queries as New adds a step to the source. Check the Applied Steps list after the dialog closes.
- Selecting the wrong query first. The selected query becomes the left table. Cancel and restart if it is the wrong one.
- Looking for the commands in the Excel grid. Merge and append run in the Power Query Editor or from the Data tab's Combine Queries menu. They are not worksheet functions.
- Reading the preview as the full result. The grid shows a sample. Row counts shown at the bottom of the window can be approximate until the query loads. The chapter on verifying a merge covers how to check them.
- Forgetting that a merge needs two existing queries. If a table is not yet a query, load it into the editor first with From Table/Range.
Summary
Merge and append are in the Home tab's Combine group in the Power Query Editor, and in Excel under Data > Get Data > Combine Queries. Each has an "as New" variant that protects your source queries. Every operation is recorded as a step in Applied Steps, and its M code is visible in the formula bar.
Exercise
You have queries named Sales_2023 and Sales_2024 and want a combined query, without changing either source. Which command do you choose in the Power Query Editor, which Applied Step name should you expect, and where can you see the M code for that step?
Show answer
Choose Home > Combine > Append Queries as New. The new query contains an Applied Step named "Appended Query". Select that step and read its M code in the formula bar (for example, Table.Combine({Sales2023, Sales2024})), or view the whole query in Home > Advanced Editor.
Exercise
You open the Merge dialog and notice that the first table is Customers, but you wanted Orders to be the left table. What should you do, and why does it matter?
Show answer
Cancel the dialog, select Orders in the Queries pane, and open Merge Queries (or Merge Queries as New) again. The selected query becomes the left table, and the left table decides which rows a left join keeps.