Merging tables using Vlookup
Combine information from tables
Combining tables was is a very day-to-day task that mostly Excel Pro User has been doing, for ages! This is simply because they are trying to retrieve information from another table and join it into a complete table. Sometimes they do that is also because they’re trying to cross checking data from another table.
This usually happened in between a transaction table or some maybe calling them the facts table and database table (or db table) “Well there are so many ways of how people calling these tables…I can go oon for 3 days if I were to list down all of em”. So, what’s the difference in between these facts table and db table?
If you would like to have the in-depth understanding towards the facts table, read this.
But, I will simply explain it in a more layman term. When I bring up the facts table in the classroom are, I will simply tell my students…Facts table are like activity table, every time when there is some sort of activity going on, it will be added to the facts table
Let’s take the factSales table as an example. Every time when a sales representative successfully closed a deal with the customer, this will then being recorded as a new line in the facts table. So first, the system will automatically generate a unique Sales ID (as most of the time this ID is a running number), then follow by the Date Time (when does it happened), the Customer ID (A unique code that represent the customer), the Staff ID (Usually is the ID of the sales representative who seal the deal) then the Amount (which is the sales figure).
Sample of fact sales transaction:
And you should expect this list will keep on expanding when there are more sales activity.
If you look into this fact sales table, it has a lot of missing information. Example, When I look at the Customer ID 1225A-O896, you might not know who this is. Now you will be needing the db table which some might call it as the dimension table. So, dimension table usually are very informative, and it should contain every information you need. It is usually very wordy, filled with descriptions etc.
An example that I’m going to talk about is the dbCustomer table. This table will lead by the very first column the Customer ID column ( the unique id that assign to each customer to represent them), then follow by the Customer Name (the friendly name of the customer), Contact Person (the contact or the in-charge person of that customer), the Email (method to reach out to the customer), Country (which region or country that the customer is being located) etc.
Sample of dbCustomer:
Alright, back to our story, now I needed some information from this dbCustomer table to be merged with the factSales table. The information that I need to be merged will be the Customer Name and the Country.
In order to get this mission complete, I will have the VLOOKUP function being setup in the factSales Table, then extract the information from the dbCutomer table.
To do that, I will first convert dbCustomer range into Table Object then rename the table to “dbCustomer”.
Now after the table conversion, this will make your selection of the table easier when it comes to VLOOKUP.
The vlookup is going to take the Customer ID from the factSales Table compared with the Customer ID from the dbCustomer Table. Once it has found its match, I will then extract the Customer Name and Country from the dbCustomer and return as output in the factSales Table.
Syntax of VLOOKUP:
=VLOOKUP(LookupValue, TableArray, ColumnIndexNumber, RangeType)
LookupValue – 1225A-O896 < VLOOKUP will use this ID to match with the Customer ID column from dbCustomer Table.
TableArray –dbCustomer < The table you would like to extract information from
ColumnIndexNumber –2 < Which column of information you would like VLOOKUP to extract (it has to be in number form)
RangeType –FALSE < FALSE: Exact Match; TRUE: Approximately Match
The complete version of the formula (Customer Name):
=VLOOKUP(1225A-O896, dbCustomer, 2, False)
If you’re going to extract the Country column, simply switch the column index number from 2 to 5. This is because Country is being located at the 5th column of the dbCustomer table.
The complete version of the formula (Country):
=VLOOKUP(1225A-O896, dbCustomer, 5, False)