How to Perform Union Query in Excel (with Detailed Steps)

In this article, we will explain how to perform a Union query in Excel to merge multiple tables with one common column or row.

Suppose we have 3 individual datasets – Sales Data, Product ID, and Region List, which are related to each other. Let’s perform a Union query to merge them into one table.

Sample Dataset to Perform Union Query in Excel


Step 1 – Collect Data and Create a New Query Connection

First we’ll prepare the datasets into tables and create connections.

  • Click on any cell inside the dataset.
  • Go to the Data tab >> From Table/Range tool.

Create Tables from Data Range to Perform Union Query in Excel

  • In the Create Table window that opens, click on OK.

Create Table Window

The Power Query Editor window will open.

  • In the Query Settings pane, under the Properties group, enter the table’s name (SalesData here) in the Name text box.

Query Settings Pane

  • Under the File tab, click on the Close & Load arrow and select the option Close & Load To…

Choose Close & Load To... Option

The Import Data window will appear.

  • Choose the Only Create Connection option and click on OK.

Import Data WIndow to Perform Union Query in Excel

The SalesData table is prepared for merging.

  • Follow similar procedures for all the other datasets to prepare them for the Union query.

The following will be visible on the right side of your Excel file in the Queries & Connections window.

All Tables to Perform Union Query in Excel

Read More: How to Create Union of Two Tables in Excel


Step 2 – Prepare to Combine the Queries

Now we are ready to perform a Union query between these tables.

  • Go to the Data tab >> Get Data tool >> Combine Queries option >> Merge option.

Choose Merge Option to Perform Union Query in Excel

The Merge window will appear.


Step 3 – Make the Necessary Selections in the Merge Window

Now we’ll perform a Union query between the SalesData table and the ProductID table.

  • In the first Preview window choose the SalesData table, and in the second Preview window choose the ProductID table.
  • Click on the common column (Product) in both tables.
  • Choose Left Outer for the Join Kind and click on OK.

Merge Window to Perform Union Query in Excel

Read More: How to Do Union of Two Columns in Excel


Step 4 – Place the Values Properly

As a result the merge will take place, but the values haven’t been placed properly.

  • Click on the double arrow button inside the ProductID header.

Click on Double Arrow Button

  • From the drop-down list that opens, tick the Product ID option only, untick the Use original column name as prefix, and click on OK.

Product ID Dropdown

The two tables are merged properly now.

Performed Union Query Between Two Tables


Step 5 – Create Another Connection

  • As we need to merge another table, go to the File tab >> Close & Load arrow >> Close & Load To… option.

Choose Close & Load To... Option

The Import Data window will appear.

  • Click on the Only Create Connection option and click on OK.

Import Data Window

We can now import the merged table as the Merge1 table.


Step 6 – Make the Necessary Selections in the Merge Window (Same as the Step 3)

We’ll repeat the merging procedures above to merge this Merge1 table and the RegionList table.

  • In the first Preview window choose the Merge1 table, and in the second Preview window choose the RegionList table.
  • Click on the Country column in both tables.
  • Choose Left Outer as the Join Kind and click on OK.

Merge Window to Perform Union Query in Excel

The RegionList column will also be merged into the previously merged table.

  • For proper values, click on the double arrow button on the RegionList header.

Click on Double Arrow Button

  • From the drop-down list that appears, tick on the Region option only and untick the option Use original column name as prefix.
  • Click on OK.

Region Header Dropdown

We have proper values in the Region column.

Performed Union Query Between Three Sheets


Last Step – Close and Load the Data

  • Under the File tab, click on the Close & Load button.

Click on Close & Load Button

We have completed merging all three tables with a Union query in Excel.

Performed Union Query Between All Data Ranges


Download Practice Workbook


Related Article


<< Go Back to Excel Union | Excel OperatorsExcel Formulas | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Tanjim Reza
Tanjim Reza

Md. Tanjim Reza Tanim, a BUET graduate in Naval Architecture & Marine Engineering, contributed over one and a half years to the ExcelDemy project. As an Excel & VBA Content Developer, he authored 100+ articles and, as Team Leader, reviewed 150+ articles. Tanim, leading research, ensures top-notch content on MS Excel features, formulas, solutions, tips, and tricks. His expertise spans Microsoft Office Suites, Automating Finance Templates, VBA, Python, and Developing Excel Applications, showcasing a multifaceted commitment to the... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo