How to Merge Queries in Power Query

In Power Query, you can merge two or more queries based on a matching column or columns.

When working with data from multiple sources, you may often need to combine these datasets based on common columns. This approach is particularly useful when you have related information spread across different tables that you want to analyze together

Let me show you how to merge multiple queries to get one single dataset in Power Query.

Suppose you have a workbook containing two tables on separate sheets as shown below.

The Sales table is on the Sales worksheet.

Sales dataset in Excel.

The Products table is on the Products sheet.

Products table data set in a sheet in Excel.

The first thing you need to do is create two queries—Sales and Products—in Power Query based on the tables..

The queries you want to merge must have at least one common column with matching values that can act as the key for the merge. The common column should contain unique values in at least one of the queries to ensure accurate matching. In this example, the matching column in both queries is ProductID.

Create the Queries

Here are the steps you can use to create the two queries:

  1. Click the Data tab.
  2. Open the Get Data drop-down on the Get & Transform Data group, and click the Launch Power Query Editor option.
Launch Power Query Editor

The above step opens the Power Query Editor.

  1. On the Power Query Editor, open the New Source drop-down on the Ribbon’s far right, hover the mouse pointer over the File option, and click the Excel Workbook on the submenu.
Click on the Excel workbook option.

The above step opens the Import Data dialog box.

  1. On the Import Data dialog box, navigate to the folder where the target workbook is stored, select it, and click the Import command button.
Select the file that has the worksheets

The above step opens the Navigator feature.

  1. On the Navigator feature, check the ‘Select multiple items’ option, select the Products and Sales tables, and click OK.
Check the 'Select multiple items' option and then select the sheets that have the table.

The above step creates the Sales and Products queries in the Power Query Editor.

The two queries are now listed in the Queries navigation pane.

Merge the Queries

You can now merge the Sales and Products queries using the steps below.

  1. Select the Sales query, which is the primary query where you want to add the product name and price columns from the Products query.
  2. Open the Merge Queries drop-down on the Combine group.
Click on the 'Merge Queries' option.

The Merge Queries drop-down shows two options: Merge Queries and Merge Queries as New. 

Use the Merge Queries option to merge the primary query with another query and get the results in the primary query itself.

Use Merge Queries as New option to create a new query by merging the primary query with another one, while keeping the original queries unchanged.

In this example, I will go with the Merge Queries as New option.

  1. Click the Merge Queries as New option on the Merge Queries drop-down list.

The above step opens the Merge feature with the primary query (Sales) already selected.

  1. On the Merge feature, select the second query (Products) from the second drop-down.
Select the two queries you want to merge
  1. Select the matching column in both queries—in this case, ProductID—leave the default join type as Left Outer, and click OK.
Select the key column in both the queries that you want to merge.

The above step creates a new query named ‘Merge1’, which includes a new merged column with a table icon. You can rename this query to something more meaningful—for example, I’ve renamed it ‘Sales_Products.’

  1. Expand the merged column and select the columns you want to bring into the primary query, using the steps below.
  • Click the Expand icon in the header of the Products merged column.
  • Uncheck the Select All Columns option.
  • Select the ProductName and Price (USD) columns.
  • Uncheck the ‘Use original column name as prefix’ option.
  • Click OK.
Select the columns that you want to appear in the merged table, in the merged query.

The above step brings the ProductName and Price (USD) columns into the new query.

  1. Rearrange the new columns in the merged query to more logical positions, as shown below.
Rearrange the new columns in the new merged query
  1. Click the Close & Load command button on the Close group.
Click on the 'Close and Load' option.

The above step saves changes to the merged query, closes the Power Query Editor, and loads the results to a new sheet.

Result of the merged queries

I have shown you how to merge queries in Power Query. I hope you found the tutorial helpful.

Other Excel articles you may also like:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.