Professional Documents
Culture Documents
XLookUp - 5 Examples
XLookUp - 5 Examples
• LOOKUP
• VLOOKUP
• HLOOKUP
• INDEX/MATCH
This will be just a glimpse of some of the many and varied uses of the XLOOKUP function. We will
explore many more uses of XLOOKUP in future videos.
Availability
As of the writing of this post (September 2019), the XLOOKUP function is only available to Office 365
users who are members of the “Office Insiders” channel. XLOOKUP is soon to be released to all Office 365
users, so keep checking those Office updates.
We would like to find an employee name from the list below and return the Division that the user was
originally assigned and place the result in Column C.
We would also like to calculate the employee’s Bonus based on the Yearly Sales (Column B) and place the
results in Column E.
The calculations for the Bonus are based on the following table.
Basic Lookup
Let’s begin by looking up the user’s Division. We’ll select the first empty cell below our Division heading
and enter the following formula.
NOTE: There are three additional optional arguments that we will examine later in the post.
We have “locked” the references to the lookup_array ($D$5:$D$37) and return_array ($B$5:$B$37) since
we want those references to remain the same when we fill the formula down the list of names.
If you don’t want to deal with relative/absolute references, consider converting the data to a proper Excel
Table to use structured references instead of traditional cell references.
Notice that we didn’t have to tell XLOOKUP to perform an exact match lookup because XLOOKUP
defaults to exact match. Unlike VLOOKUP/HLOOKUP where you had to expressly tell them to perform an
exact match, we don’t need to define anything for this behavior.
Fill the XLOOKUP formula down the list to see the results.
Did you see the hidden awesomeness?
Notice that in the data, the column that we are returning data from is to the LEFT of the column we are
searching.
This would be impossible with a traditional VLOOKUP function (without performing some crazy in-
memory, virtual table construction which only 9 people on planet Earth find enjoyable.)
This is because “Kim” was originally assigned to the “Utility” Division upon initial hiring but was then
transferred to the “Game” Division a few years later.
Like the VLOOKUP function, XLOOKUP returned the Division for the first discovered instance of “Kim
West” in the Name column.
NOTE: The two additional arguments are optional, hence the square brackets.
• [if_not_found] – is what to display if no match exists (e. text message or default value)
• [match_mode] – specifies the Match Type. (0 = Exact match {default}, -1 = Exact match or next
smaller, 1 = Exact match or next larger, 2 = Wildcard match)
• [search_mode] – specifies the Search Mode. (1 = Search first to last {default}, -1 = Search last to
first, 2 = Binary search {ascending}, -2 = Binary search {descending})
In our case, we are performing an exact match (0) from the last record to the first record (-1) and we will
display a message (“Not Found”) if there is not a match .
We see that “Kim West” began her employment working in the “Utility” Division, but currently resides in
the “Game” Division.
Since the table establishes ranges of salaries, the odds are slim that we will search for a value that is defined
in the Salary column. Instead, we will need to return the Bonus for the Salary that is the closest without
going over.
Select the first empty cell below our Bonus heading and enter the following formula.
Remember, the -1 in the [match_mode] argument means “exact match or next smaller item”.
This means you can sort your lists ANY WAY YOU WISH, and the lookup still works.
We will explore many other ways to use XLOOKUP in future tutorials. For now, give it a try and be
amazed.
Excel’s XLOOKUP
5 Examples
By now, you may have read about Excel’s new super lookup function called XLOOKUP.
XLOOKUP has the promise of becoming the only lookup function you’ll ever need for virtually any lookup
problem you encounter. This will be a welcomed addition to Excel for those that struggle with
VLOOKUP/HLOOKUP are just completely give up all hope when working with INDEX/MATCH
functions.
Since its debut a few months ago, some enhancements to the function have been made that make it bigger
and better than ever.
This post will examine some of the newest enhancements to XLOOKUP as well as explore some additional
uses that were not covered in the previous XLOOKUP post a few months earlier.
Our mission is to calculate the maximum bonus each employee can achieve.
On a separate tab (named “B_Master”), we have a list of employee IDs, their bonus percentage, and the
employee names.
We aren’t working with a tiered bonus scheme; each employee can have their own bonus percentage.
We want to bring the bonus percentages located on the “B_Master” sheet and place them in Column C next
to their respective employees on the “Salary” sheet.
Since we don’t have the IDs on the “Salary” sheet, we’ll create a lookup formula that uses the employee
names.
On the “Salary” sheet, select cell C3 and enter the following formula:
NOTE: The default match mode for XLOOKUP is to perform an exact match, unlike VLOOKUP’s
approximate match default mode.
Fill the formula down the adjacent rows to repeat the formula for each employee.
Notice that the XLOOKUP function returned #N/A error for any employee name that was not found on the
“B_Master” sheet.
To gracefully handle these errors, we will use the 4th, optional argument named [if_not_found] to reprogram
the default error message with something more mathematically-friendly.
Fill the formula down the adjacent rows to update the formula for each employee.
Horizontal Lookup
What would we do if the table were arranged left-to-right?
In the “old days” we would perform a horizontal lookup with the HLOOKUP function instead of a vertical
lookup using the VLOOKUP function.
Let’s perform the same task are the previous example, calculating a bonus amount, but this time we will find
the employee name on Row 5 and the percentage on Row 4 of the “B_Master” sheet.
On the “Salary” sheet, select cell D3 and enter the following formula:
=XLOOKUP(A3, B_Master!$F$5:$AD$5, B_Master!$F$4:$AD$4, 0) * B3
Fill the formula down the adjacent rows to repeat the formula for each employee.
SPECIAL NOTE: In both examples, the range of names being searched was located AFTER the range of
percentages being returned. This would be impossible with a traditional VLOOKUP or HLOOKUP
function.
We’ll begin by placing the employee’s last name in cell F3, then select cell G3 and enter the following
formula.
Because the wildcard character “*” (asterisk) is a text character, we must enclose the asterisk within a set of
double-quotes prior to concatenating the character to the F3 cell reference.
The lookup fails because we are not using the correct match mode.
Remember, the default match mode is to perform an exact match. We need to select the optional argument
[match_mode] and set it to option 2 – Wildcard character match.
If you don’t wish to use the [if_not_found] argument, you will need to account for the argument position by
placing an extra comma after the return_array argument.
Two-Way Lookup
For our example, we have the following table.
A two-way lookup operates by first searching for an item within a column of data.
Next, a second search is performed to locate an item across a row of data.
Once these two pieces of information are located, the intersection of the discovered row and column is
derived, and the data contained at that intersection is returned.
To make user selections easier, we will create two Data Validation lists: one for the Employee
(=$A$3:$A$20) and one for the adjacent column’s headers (=$B$2:$D$2).
Select cell F3, then click Data (tab) -> Data Tools (group) -> Data Validation.
In the Data Validation dialog box, set the Allow dropdown to List and the Source field to =$A$3:$A$20.
Select cell F4, then click Data (tab) -> Data Tools (group) -> Data Validation.
In the Data Validation dialog box, set the Allow dropdown to List and the Source field to =$B$2:$D$2.
Select an employee from the dropdown in cell F3 and a category from the dropdown in cell F4.
Our goal is to see the value associated with the selected employee and the selected category.
Test the formula by selecting various combinations of employees (F3) and categories (F4).
Approximate Match Lookup
Continuing with our previous example, suppose the company has received a new bonus scheme.
Anyone earning up to just under 30,000 does not receive a bonus. From 30,000 to just under 50,000, the
employee earns a 5% bonus on their yearly salary. From 50,000 to just under 60,000 they receive an 8%
bonus, and so on.
Although we wish to calculate the bonus amount, we first need to determine the applicable bonus
percentage. Once the bonus percentage is determined, we will multiply the percentage against the yearly
salary to arrive at the bonus amount.
On the “Salary” sheet, select cell E3 and enter the following formula.
NOTE: We are skipping the [if_not_found] argument, so we need to make sure we place 2 commas to
account for the unused argument.
Because XLOOKUP defaults to “exact match” mode, we are using the “-1” option for the [match_mode]
argument. If we fail to locate an exact match of the salary, we want to return the next closest bonus that
doesn’t exceed the salary.
We see that Gary Miller, with a yearly salary of 60,270, receives a bonus percentage of 10%.
60,000 is the closet salary to Gary’s 60,270 without going over.
Fill the formula down to the remaining employees and we see the following results.
Because we wanted to calculate the bonus amount, not find the bonus percentage, we will return to cell E3
and modify the formula to multiply the discovered bonus percentage by the employee’s yearly salary.
Fill the formula down the column to replicate the updated formula.