Use Power Query To Consolidate Data From Two Excel Workbooks
Excel is one of the most widely used software programs in the world – and with good reason. It is a powerful tool for handling large amounts of data, and it’s so flexible that you can use it for almost any type of reporting and calculation.
But even the best fall short sometimes, and handling, manipulating and matching big data in sheets can be a tedious and tiresome process because Excel is not made for being a “real” database program.
Luckily, Microsoft has fixed some of this with the Power Query tool, which makes it possible for ordinary users to treat Excel as a database when it comes to handling data from different sources.
In this guide, I will walk you through how to consolidate data from two different Excel workbooks. One of the workbooks (the one called ‘Products.xlsx’) contains sample product data from a company that sells furniture. In this case, I have made it very simple for you and the data consist of a column with a product number (column A) and a column with a product name (column B).
The second workbook (called ‘UnitsInStock.xlsx’) contains the quantity of these products that are currently in stock. The product numbers are in column A and the quantity is in column B.
Download the sample workbooks ‘Products workbook’ and ‘UnitsInStock workbook’.
What we want is for the data to be consolidated in one spreadsheet consisting of three columns. One with the product numbers (column A), one with the product names (column B) and one with the quantity in stock (column C).
![Picture 1]()
To show you the strength of Power Query I’ve mixed up the order of the products. This means that you can’t just copy column B from the ‘UnitsInStock’-workbook and put in column C of the ‘Products’-workbook. You need a way to make the conjoined data match each other so the correct quantity in stock is placed in the same row as the corresponding product.
This guide and all examples are based on Excel 2016 for Windows where Power Query is already built in. If you use Excel 2010/2013 you can download the Power Query add-in directly from Microsoft right here.
Getting Started
Open up a blank worksheet, then navigate to the ‘Data’ pane on the ribbon. In the section ‘Get & Transform’ click the ‘New Query’, hover your mouse over ‘New file’ and choose ‘From Workbook’.
![Picture 2]()
In the next dialog box, locate the workbook ‘Products.xlsx’ and click ‘OK’.
Now a larger dialog box appears where you can select and load or edit the data you want to put into the ‘Power Query Editor’. Click the ‘Products’ sheet and then click ‘Edit’ in the lower right corner of the dialog box.
![Picture 3]()
Loading both workbooks into Power Query
Now you’ve entered the actual ‘Power Query Editor’ and you might notice that the design and layout don’t look much like Excel, but more like a “real” database (e.g. Microsoft Access). The data that is loaded into the editor now consists of the product numbers and the product names. To add the quantity in stock you need to add an additional source (the ‘UnitsInStock.xlsx’ workbook).
To do that, click the ‘New Source’ button on the ‘Home’ tab of the ribbon in the editor. Then hover your mouse over ‘File’ and click ‘Excel’.
![Picture 4]()
Locate the ‘InStock’ sheet, just like you did before with the ‘Products.xlsx’-file and click ‘OK’.
Merging the data
Now look at the left pane of the editor. Here you see a title (“Queries [2]”). By now the ‘InStock’ query should be selected. Make sure that you change that to the ‘Products’ query and then proceed with the following.
Click the ‘Merge Queries’-button just to the left of the ‘New Source’-button you clicked moments ago.
In the new dialog box for merging queries. Follow the steps in the picture below.
![Picture 5]()
In step 2 and 3 you select which ‘identifier’ the merging will follow. This means that if the example was set up with the product numbers in column 2 in the ‘UnitsInStock.xlsx’-file, then the second column would have to be selected in the ‘InStock’ query instead of the first.
Complete the merging by clicking ‘OK’.
When you return to the data you find a column named ‘NewColumn’ added next to the ‘ProductName’ column. Click the ‘Expand’-button, unselect ‘Product#’ and click ‘OK’.
![Picture 6]()
Now the data has been merged and has the desired layout. But we need the data in a spreadsheet and not some editor.
Loading the data into Excel
To get the data from the editor and into Excel click ‘Close & Load’ in the ‘Home’ tab on the ribbon in the editor.
The new table is inserted in a new sheet in the blank workbook you created when you started this guide. It should look like this.
![Picture 7]()
Refreshing data
When changes are made (entry-changes, not structural changes) you can update the new table in Excel by right-clicking it and clicking ‘Refresh’ and the data gets updated instantly. This means when the units in stock gets updated with new quantities or more products are added to the workbooks, it will automatically be included in the consolidated sheet when you refresh it.
This is one of the powerful features of using queries in Excel.
Wrapping up
Congratulations! You’ve just consolidated data from two workbooks into one sheet using Power Query.
The clever reader might notice that in this simple example you could just as easily have used a VLOOKUP to achieve the same, but this serves as a general introduction and example to using Power Query in Excel.
Power Query is far superior to mere functions and features when it comes to manipulating very large sets of data, especially from sources outside of Excel. For a brief moment, you might actually think that you are using Microsoft Access. This gives you several options for data-handling that Excel in itself (without Power Query) cannot handle this fast on its own.
If you want to learn more about Power Query and especially how to consolidate data from multiple (different) data sources, you should attend BizNet Softwares complimentary webinar “Consolidating Multiple Data Sources in Excel with BizConnectors from BizNet Software” on May 25th at 1030 CDT Register Here
This guide is written by Kasper Langmann of spreadsheeto.com.
The post Use Power Query To Consolidate Data From Two Excel Workbooks appeared first on BizNet Software.