0% found this document useful (0 votes)
112 views20 pages

Join Two or More Tables in Excel With Power Query

xcel With Power Query

Uploaded by

Farzaneh Sedighi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views20 pages

Join Two or More Tables in Excel With Power Query

xcel With Power Query

Uploaded by

Farzaneh Sedighi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

How to join tables in Excel: Power Query vs.

Nov
Merge Tables Wizard
14 by Svetlana Cheusheva | updated on May 30, 2019 3 Comments

In this tutorial, we will look at how you can join tables in Custom Searc
Excel based on one or more common columns by using
Power Query and Merge Tables Wizard.

Combining data from multiple tables is one of the most Excel: featured articles
daunting tasks in Excel. If you decide to do it manually, Merge multiple Excel sheets
you may spend hours only to nd out that you've into one
messed up important information. If you are an
Combine Excel les into one
experienced Excel pro, then you can possibly rely on
VLOOKUP and INDEX MATCH formulas. A macro, you Compare 2 Excel les/sheets
believe, could do the job in no time, if only you knew
Merge 2 columns in Excel
how. The good news for all Excel users - Power Query or
Merge Tables Wizard can be your time-saver. The choice Compare 2 columns in Excel for
is yours. matches and di erences

How to join tables with Power Query How to merge two or more
tables in Excel
Merge Tables Wizard - quick way to combine tables in
Excel CONCATENATE in Excel:
combine text strings, cells and
Other ways to combine data in Excel columns

Create calendar in Excel (drop-

How to join tables with Excel down and printable)

3 ways to remove spaces


Power Query between words in Excel cells

In simple terms, Power Query (also known as Get & Сalculate time in Excel - time
Transform in Excel 2016 and Excel 2019) is a tool to di erence, adding / subtracting
combine, clean and transform data from multiple times
sources into the format you need such as a table, pivot
Сonvert text to number in Excel
table or pivot chart.

Among other things, Power Query can join 2 tables into Outlook: featured articles  
1 or combine data from multiple tables by matching
  How to x "Cannot start
data in columns, which is the focus of this tutorial.
Awesome!!!
For the results to meet your expectations, please keep
Microsoft Outlook. Unable to
open Outlook window" error
Sheila Blanchard
in mind the following things:
Merge duplicate contacts

Power Query is a built-in feature in Excel 2016 and Outlook Quick Parts and
Power Query is a built-in feature in Excel 2016 and Outlook Quick Parts and
Excel 2019, but it can also be downloaded in Excel AutoText: how to create, edit
2010 and Excel 2013 and used as an add-in. In earlier and use
versions, some windows may look di erent from the
images in this tutorial that were captured in Excel
Ultimate Suite 2018.5 for Excel
Google Sheets: featured
2016. articles
For the tables to be combined correctly, they should Merge data from duplicate rows
have at least one common column (also referred to as based on a unique column
a common id or key column or unique identi er). Also,
the common columns should contain only unique How to compare data in two
values, with no repeats. Google sheets or columns

The source tables can be located on the same sheet Google Sheets VLOOKUP with
or in di erent worksheets. examples

Unlike formulas, Power Query does not pull data from


one table to another. It creates a new table that
combines data from the original tables.
Excel formulas
The resulting table does not update automatically.
You should explicitly tell Excel to do this. Please see Excel functions
how to refresh a merged table. Vlookup in Excel
Merge data in Excel SumIf

Source data Excel CountIf Excel Compare

As an example, let's join 3 tables based on the common Excel If statement


columns Order ID and Seller. Please note that our tables Excel Charts Pivot Table
have di erent numbers of rows, and although table 1 Updates
has duplicates in the Seller column, table 3 contains only
Excel conditional formatting
unique entries.
Excel formatting Excel time

Excel duplicates Excel date

Excel tips Excel macro


Outlook Google Sheets
Outlook duplicates Outlook templates

Sign in
Log in / Register

Our task is to map the data in table 1 with the relevant  


  records from the other two tables, and combine all the

Awesome!!!
Sheila Blanchard

data into a new table like this:


data into a new table like this:

Ultimate Suite 2018.5 for Excel

Before you start joining, I'd advise you to give some


descriptive names to your tables, so it will be easier for
you to recognize and manage them later. Also, although
we say "tables", you do not actually need to create an
Excel table. Your "tables" could be usual ranges or
named ranges as in this example:

Table 1 is named Orders

Table 2 is named Products

Table 3 is named Commissions

Create Power Query connections


Not to clutter your workbook with copies of your
original tables, we are going to convert them into
connections, do the merge within the Power Query
Editor, and then load only the resulting table.

To save a table as a connection in Power Query, here's


what you do:

1. Select your rst table (Orders) or any cell in that table.

2. Go to the Data tab > Get & Transform group and click
From Table/Range.

 
 

Awesome!!!
Sheila Blanchard
Ultimate Suite 2018.5 for Excel

3. In the Power Query Editor that opens, click on the


Close & Load drop-down arrow (not the button
itself!) and select the Close and Load To… option.

4. In the Import Data dialog box, select the Only Create


Connection option and click OK.

 
 

Awesome!!!
Sheila Blanchard

This will create a connection with the name of your


This will create a connection with the name of your
table/range and display that connection in the
Queries & Connections pane that appears on the
right-hand side of your workbook.
Ultimate Suite 2018.5 for Excel
5. Repeat the above steps for all other tables you want
to merge (two more tables, Products and
Commissions, in our case).

When nished, you will see all the connections on the


pane:

Merge two connections into one


table
With the connections in place, let's see how you can join
two tables into one:

1. On the Data tab, in the Get & Transform Data group,


click the Get Data button, choose Combine Queries in
the drop-down list, and click Merge:

 
 

Awesome!!!
Sheila Blanchard

2 In the Merge dialog box do the following:


2. In the Merge dialog box, do the following:

Select your 1st table (Orders) from the rst drop-


down.

Select your 2nd table (Products) from the second


Ultimate Suite 2018.5 for Excel
drop-down.

In both previews, click on the matching column


(Order ID) to select it. The selected column will get
highlighted in green.

In the Join Kind drop-down list, leave the default


option: Left Outer (all from rst, matching from
second).

Click OK.

Upon completion of the above steps, the Power Query


Editor will show your rst table (Orders) with one
additional column named like your second table
(Products) added to the end. This additional column
does not have any values yet, just the word "Table" in all
the cells. But don't feel discouraged, you did everything
right, and we are going to x that in a moment!

Select the columns to add from the  


  second table
Awesome!!!
At this point, you have a table resembling the one in the
screenshot below. To complete the merging process, Sheila Blanchard

perform the following steps within the Power Query


perform the following steps within the Power Query
Editor:

Ultimate Suite 2018.5 for Excel


1. In the added column (Products), click on the two-
sided arrow in the header.

2. In the box that opens, do this:

Keep the Expand radio button selected.

Unselect all columns, and then select only the


column(s) you want to copy from the second table.
In this example, we select only the Product column
because our rst table already has Seller and Order
ID.

Uncheck the Use original column name as pre x


box (unless you want the column name to be
pre xed with the table name from which this
column is taken).

Click OK.

As the result, you will get a new table that contains every
record from your rst table and the additional column(s)

 
 

Awesome!!!
Sheila Blanchard

from the second table:


from the second table:

Ultimate Suite 2018.5 for Excel

If you need to merge only two tables, you may consider


the work almost done and go load the resulting table in
Excel.

Merge more tables (optional)


In case you have three or more tables to join, there is
some more work for you to do. I will outline the steps
brie y here, because you have already done all this
when joining the rst two tables:

1. Save the table you've got in the previous step (shown


in the screenshot above) as a connection:

In the Power Query Editor, click Close & Load drop-


down arrow and select Close and Load To….

In the Import Data dialog box, select Only Create


Connection, and click OK.

This will add one more connection, named Merge1, to


the Queries & Connections pane. You can rename
this connection if you want (right-click and select

 
 

Awesome!!!
Sheila Blanchard

Rename in the pop-up menu)


Rename in the pop-up menu).

Ultimate Suite 2018.5 for Excel

2. Combine Merge1 with your third table (Commissions)


by performing these steps (Data tab > Get Data >
Combine Queries > Merge).

The screenshot below shows my settings:

3. Clicking OK in the Merge dialog box opens the Power


Query Editor, where you select the columns to be  
  added from table 3.

Awesome!!!
Sheila Blanchard

In this example we add only the Commission column:


In this example, we add only the Commission column:

Ultimate Suite 2018.5 for Excel

As the result, you get a merged table that consists of the


rst table, plus the additional columns copied from the
other two tables.

Import the merged table to Excel


With the resulting table in the Power Query Editor, there
is just one thing left for you to do - load it in your Excel
workbook. And it is the easiest part!

1. In the Power Query Editor, click the Close & Load drop-
down arrow, and choose Close and Load To….

2. In the Import Data dialog box, select Table and New


Worksheet options.

3. Click OK.

A new table combining the data from two or more


sources appears in a new worksheet. Congratulations,
you did it!
 
 
As a nishing touch, you may want to apply the right
Awesome!!!
number format to some columns and maybe change
the default table style to your favorite one. After these Sheila Blanchard

improvements my combined table looks very nice:


improvements, my combined table looks very nice:

Ultimate Suite 2018.5 for Excel

Tip. If your tables contain numeric data (e.g. sales


numbers or quantity) and you want a quick
summary, you can load the resulting table as a
PivotTable Report or create a pivot table in the
usual way (Insert > PivotTable).

How to join tables based on multiple


columns with Power Query
In the previous example, we were combining tables by
matching data in one key column. But there is nothing
that would prevent you from selecting two or more
column pairs. Here's how:

In the Merge dialog box, hold the Ctrl key and click on
the key columns one-by-one to select them. It is
important that you click on the columns in the same
order in both previews, so the matching columns have
the same numbers. For example, Seller is key column 1
and Product is key column 2. Blank cells or rows that

 
 

Awesome!!!
Sheila Blanchard

Power Query is unable to match show null:


Power Query is unable to match show null:

Ultimate Suite 2018.5 for Excel

After that, perform exactly the same steps as described


above, and your tables will be merged by matching
values in all the key columns.

How to update/refresh the merged


table
The best thing about Power Query is that it is a one-time
setup. When you make some changes to a source table,
you don't have to repeat the whole process again.
Simply, click the Refresh button on the Queries &
Connections pane, and the merged table will update at
once:

 
 

Awesome!!!
Sheila Blanchard

If the pane has disappeared from your Excel click the


If the pane has disappeared from your Excel, click the
Queries & Connections button on the Data tab to get it
back.

Or click the Refresh button on the Query tab in the Load Ultimate Suite 2018.5 for Excel
group (this tab activates once you select any cell within a
merged table):

Merge Tables Wizard - quick


way to join 2 tables in Excel
Now that you are familiar with the inbuilt tool, let me
show you our approach to merging tables in Excel.

In this example, we will be combining the same tables


that we joined with Power Query a moment ago. I have
just added a few more rows to the second table to show
you more capabilities of our add-in:

With the Merge Tables Wizard installed in your Excel,


here's what you need to do:

1. Select the rst table or any cell in it and click the


Merge Two Tables button on the Ablebits Data tab:

 
 

Awesome!!!
Sheila Blanchard
Ultimate Suite 2018.5 for Excel

2. Take a quick look at the selected range to make sure


the add-in got it right and click Next.

3. Select the second table and click Next. Please note


that our second table contains 26 rows compared to

 
 

Awesome!!!
Sheila Blanchard

only 10 rows in the rst table:


only 10 rows in the rst table:

Ultimate Suite 2018.5 for Excel

4. Choose one or several matching columns and click


Next. Since we are joining two tables by one common
column, Order ID, we select only that column:

Please notice the Case-sensitive matching box at the


top. Select it if you want to treat uppercase and
lowercase text in the key columns as di erent
characters. For this example, we don't need that, so
we leave the box unselected.

5. Select the columns to update in the rst table. This


step is optional, and if you don't want any updates,
you can click Next without selecting anything here.  
 
We select the Seller column because we have more
Awesome!!!
rows in the second table and we want the new seller
Sheila Blanchard

names to appear in the existing Seller column:


names to appear in the existing Seller column:

Ultimate Suite 2018.5 for Excel

6. Choose the column(s) to be added to the rst table,


Product in our case, and click Next:

7. This step is very important because it determines


how your tables will be merged.
In this example, we go with the default options
shown in the screenshot below. But I'd like to draw
your attention to the following 2 boxes that can
prevent overwriting your existing data in case you've
chosen to update some columns:

Empty cells only  


 
Only if cells in the lookup table contain data
Awesome!!!
Sheila Blanchard
Ultimate Suite 2018.5 for Excel

Make your choices, click Finish, allow the wizard a few


seconds for processing, and examine the results.

With the default options, the wizard highlights the newly


added rows and adds the Status column. If you don't
want any of that, clear the corresponding boxes in the
last step.

 
 

Awesome!!!
To join three and more tables, simply repeat the above
Sheila Blanchard
steps. Just remember to select the result of a previous
merge as your main table.
Unlike Power Query the Merge Tables Wizard does not
Unlike Power Query, the Merge Tables Wizard does not
keep a connection between the resulting and source
tables. In some situations, this may be a disadvantage.
On the plus side, no matter what you do with the source
table - edit, move or even delete - the merged table
Ultimate Suite 2018.5 for Excel
remains intact.

This example has shown just one scenario that our


wizard can handle, but there is much more to it! If you
are curious to know other use cases, please check out
these examples. Or you can download a 7-day trial
version of the Merge Tables Wizard and see for yourself.
If you like the add-in and decide to get a license, we will
gladly o er you the 15% o coupon code that we've
created especially for our blog readers: AB14-BlogSpo .

In case you are looking to join tables in some other way,


you may nd the following resources useful.

Other ways to combine data


in Excel:
Merge tables by column headers - join two or more
tables based on column names. You can choose to
combine all the columns or only the ones you select.

Combine multiple worksheets into one - copy multiple


sheets into one summary worksheet. Of course, it's not
manual copy/pasting! You only indicate which
worksheets to merge, and our Copy Sheets tool does the
rest.

Compare two Excel les - how to compare two tables


(worksheets) for di erences and merge them into a
single sheet.

3 Responses to "How to join tables in Excel: Power Query vs.


Merge Tables Wizard"
1 Hernan Torres says:  
  January 20, 2019 at 4:15 am

Other way: Awesome!!!


Note: I use Power Query (M Language) Sheila Blanchard
In this example I have two tables and this function (myfunction)
cuentas(id,label,systype)
datos(periodo cuenta monto)
datos(periodo,cuenta,monto)
(myfunction)=>

let
Ultimate Suite 2018.5 for Excel
Source = Table.NestedJoin(datos,{"cuenta"},cuentas,{"ID"},"unionall",JoinKind.LeftOuter),
#"Expanded unionall" = Table.ExpandTableColumn(Source, "unionall", {"LABEL", "SYSTYPE"},
{"LABEL", "SYSTYPE"})
in
#"Expanded unionall"

Then when I use "myfunction", I generate one table whit two additional colums, one with the
label and other with account type for every cuenta in the table datos.
"ID" is unique over the table "cuentas", and cuentas have many entries in the transactional
table (datos) in the eld "cuenta".

Regards from Maracaibo, Venezuela

Reply

2 Mahab says:
July 2, 2019 at 5:11 am

Hi Svetlana
Thanks for this great post. I have 3 worksheets (Tables) that I want to join in one worksheet
(Table). I tried it as you described using power query, but at nal step I get following error:
"Initialization of the data source failed.
Check the database server or contact your database administrator. Make sure the external
database is available, and then try the operation again. If you see this message again, create a
new data source to connect to the database."

There isn't any external database! All tables in the one le (workbook).
Could you please advise me.
Thanks in advance.

Reply

3 Win Soe says:


July 25, 2019 at 2:25 pm

I can't see Join Kind in excel 2016, Please.

Reply

Post a comment
Name Name

 
[email protected] E-mail (not published)
 

Awesome!!!
Sheila Blanchard
Ultimate Suite 2018.5 for Excel

Send

Unfortunately, due to the volume of comments received we cannot guarantee that we will be
able to give you a timely response. When posting a question, please be very clear and concise.
We thank you for understanding!

Copyright © 2003 - 2019 4Bits Ltd. All rights reserved.   Privacy policy   Terms of use   Contact us
Microsoft and the O ce logos are trademarks or registered trademarks of Microsoft Corporation. Google Chrome is a trademark of
Google LLC.

 
 

Awesome!!!
Sheila Blanchard

You might also like