Vlookup is one of the most common tasks in excel and of-course you can always write a Vlookup formula for that but doing a Vlookup using Power Query has 2 main wins
- Vlookup in Power Query is really fast
- It’s automated, you just have to do this once
If you did not know, you can do a really fast vlookup using excel too but this post is about how can you do a Vlookup in Power Query
Watch the Full Video
Assume 2 Data Sets
Transactions Table (where you’ll typically write the Vlookup formula) & Source Data Table (where the search will be made)
IMPORTANT NOTE – For performing a Vlookup, both these data sets have to be loaded as queries in the same excel file.
Step 1 Loading Source Data as a Query
In the file where you have to perform Vlookup (i.e. transactions table file) perform the following tasks
- Go to Data (in excel 2016, power query is in Data Tab, else you’ll have a separate power query tab)
- Get Data
- From File
- From Workbook
Import the source file (in this case – Data) in the Import Box
Select the sheet (in this case – Sheet 1) in which contains the data and hit on Edit
- You’ll see all the data gets loaded in your query editor, I have additionally given a better name to my query (i.e. Data)
- Then in the Home Tab click on Close and Load To
- And then choose Only Create Connection
You’ll see the query will be displayed in the Query’s Pane
Step 2 Creating a query for Second Data
Remember I mentioned that both data sets have to be loaded as queries in the same excel file
- Click anywhere in your transactions table
- Data Tab
- From Table/Range
You’ll see the transactions table will be loaded in the query editor
Step 3 Performing Vlookup
Finally its time now for Vlookup. Here is how you do it, once you have loaded source data and transactions data in power query
- Click on Merge Queries in the Home Tab
- Select the second table as Data in the Merge Box
- From Transactions Table select the common column (tr code)
- From Data Table select the common column (tr code)
- Make sure the Join Kind is Left Outer (which is equivalent to Vlookup)
- Ok
You’ll see a separate Data Column along with transactions numbers
- Click on the double arrow to expand the column names
- Choose the columns that you need (in our case value and manager)
- Done!
Vlookup Completed
- You can see that you now have Value and Manager looked up from the Data table
- Just click on Close on Load and Power Query will dump this data on a new sheet (in a few seconds)
Automation
2 Super cool things that will happen
- If you add more data to your Data Source or your Transactions Table, you just have to right click and refresh the query and the results will be updated
- You can also dump a new file (named Data) in the same folder and again on refreshing the query the result will be updated
Other Power Query Tutorials
- Convert Multiple Columns in Rows
- Vlookup Horizontally for Multiple Records
- Rank Based on 2 Conditions
- Repeat Row N Times