Explanation
Working from the inside out, the IF function in this formula, which is entered as the “table_array” argument in VLOOKUP, runs a logical test on the value in column C “Years”, which represents the number of years a salesperson has been with a company. If C5 is less than 2, then table1 is returned as the value if true. If C4 is greater than 2, table2 is returned as the value if false.
In other words, if years is less than 2, table1 is used as for table_array, and, if not, table2 is used as for table_array.
Alternate syntax
If the lookup tables require different processing rules, then you can wrap two VLOOKUP functions inside of an IF function like so:
=IF(test,VLOOKUP (value,table1,col,match),VLOOKUP (value,table2,col,match))
This allows you to customize the inputs to each VLOOKUP as needed.
Explanation
In the example shown, we want to look up employee departments and groups using VLOOKUP by matching the first and last name of an employee.
One limitation of VLOOKUP is that it only handles one condition: the lookup_value, which is matched against the first column in the table. This makes it difficult to use VLOOKUP to find a value using multiple criteria. However, if you have control over the source data, you can add a helper column that concatenates 2 or more fields together, and then give VLOOKUP a lookup value that does the same.
The helper column joins field values from columns that are used as criteria, and it must be the first column of the table. Inside the VLOOKUP function, the lookup value itself is also created by joining the same criteria.
In the example shown, the formula in I6 is:
=VLOOKUP(I4&I5,data,4,0)
Once I4 and I5 are joined, we have:
=VLOOKUP("JonVictor",data,4,0)
VLOOKUP locates “JonVictor” on the 5th row in “data”, and returns the value in the 4th column, “Marketing”.
Setting things up
To set up a multiple criteria VLOOKUP, follow these 3 steps:
- Add a helper column and concatenate (join) values from the columns you want to use for your criteria.
- Set up VLOOKUP to refer to a table that includes the helper column. The helper column must be the first column in the table.
- For the lookup value, join the same values in the same order to match the values in the helper column.
- Make sure VLOOKUP is set to perform an exact match.