The tutorial introduces XLOOKUP - the new function for vertical and horizontal lookup in Excel. Left lookup, last match, Vlookup with multiple criteria and a lot more things that used to require a rocket science degree to accomplish have now become as easy as ABC.
Whenever you need to look up in Excel, which function would you use? Is it a cornerstone VLOOKUP or its horizontal sibling HLOOKUP? In a more complex case, will you rely on the canonical INDEX MATCH combination or commit the job to Power Query? The good news is that you do not have choose anymore - all these methods are making way for a more powerful and versatile successor, the XLOOKUP function.
How is XLOOKUP better? In many ways! It can look vertically and horizontally, to the left and above, search with multiple criteria, and even return a whole column or row of data, not just one value. It has taken Microsoft over 3 decades, but finally they've managed to design a robust function that overcomes many frustrating errors and weaknesses of VLOOKUP.
What's the catch? Alas, there is one. The XLOOKUP function is only available in Excel for Microsoft 365, Excel 2021, and Excel for the web.
The XLOOKUP function in Excel searches a range or an array for a specified value and returns the related value from another column. It can look up both vertically and horizontally and perform an exact match (default), approximate (closest) match, or wildcard (partial) match.
The syntax of the XLOOKUP function is as follows:
The first 3 arguments are required and the last three are optional.
According to Microsoft, binary search is included for advanced users. It is a special algorithm that finds the position of a lookup value within a sorted array by comparing it to the middle element of the array. A binary search is much faster than a regular search but works correctly only on sorted data.
To gain more understanding, let's build an Xlookup formula in its simplest form to perform an exact lookup. For this, we will only need the first 3 arguments.
Supposing, you have a summary table with information about the five oceans on the Earth. You want to get the area of a specific ocean input in F1 (lookup_value). With the ocean names in A2:A6 (lookup_array) and areas in C2:C6 (return_array), the formula goes as follows:
=XLOOKUP(F1, A2:A6, C2:C6)
Translated into plain English, it says: search for the F1 value in A2:A6 and return a value from C2:C6 in the same row. No column index numbers, no sorting, no other ridiculous quirks of Vlookup! It just works :)
Compared to traditional VLOOKUP, XLOOKUP has many advantages. In what way is it better than VLOOKUP? Here's a list of the best 10 features that blow the doors off any other lookup function in Excel:
The following examples demonstrate the most useful XLOOKUP features in action. Additionally, you will discover a couple non-trivial uses that will take your Excel lookup skills to a new level.
The XLOOKUP function can do both with the same syntax. The difference is in what you provide for the lookup and return arrays.
For v-lookup, supply columns:
=XLOOKUP(E1, A2:A6, B2:B6)
For h-lookup, enter rows instead of columns:
=XLOOKUP(I1, B1:F1, B2:F2)
In earlier versions of Excel, INDEX MATCH formula was the only reliable way to look to the left or above. Now, you no longer need to combine two functions where one would suffice. Just specify the target lookup array, and XLOOKUP will handle it without a problem regardless of its location.
As an example, let's add the Rank column to the left of our sample table. The goal is to get the rank of the ocean input in F1. VLOOKUP would stumble here because it can only return a value from a column to the right of the lookup column. An Xlookup formula copes with ease:
=XLOOKUP(F1, B2:B6, A2:A6)
In a similar manner, you can look above when searching horizontally in rows.
The match behavior is controlled by the 5th argument called match_mode. By default, an exact match is performed.
Please pay attention that even when you choose an approximate match (match_mode set to 1 or -1), the function will still search for an exact match first. The difference is in what it returns if an exact lookup value is not found.
This is the option you probably use 99% of the time you do lookup in Excel. Since an exact match is XLOOKUP's default behavior, you can omit match_mode and supply only the first 3 required arguments.
In some situations, however, an exact match won't work. A typical scenario is when your lookup table does not contain all the values, but rather "milestones" or "bounds" like quantity-based discounts, sales-based commissions, etc.
Our sample lookup table shows the correlation between exam scores and grades. As you can see in the screenshot below, an exact match works only when the score of a particular student matches the value in the lookup table exactly (like Christian in row 3). In all other cases, an #N/A error is returned.
=XLOOKUP(F2, $B$2:$B$6, $C$2:$C$6)
To get the grades instead of #N/A errors, we need to look for an approximate match as shown in the next example.
To perform an approximate lookup, set the match_mode argument to either -1 or 1, depending on how your data is organized.
In our case, the lookup table lists the lower bounds of the grades. So, we set match_mode to -1 to search for the next smaller value when an exact match is not found:
=XLOOKUP(F11, $B$11:$B$15, $C$11:$C$15, ,-1)
For example, Brian has the score of 98 (F2). The formula searches for this lookup value in B2:B6 but cannot find it. Then, it searches for the next smaller item and finds 90, which corresponds to grade A:
If our lookup table contained the upper bounds of the grades, we would set match_mode to 1 to search for the next larger item if an exact match fails:
=XLOOKUP(F2, $B$2:$B$6, $C$2:$C$6, ,1)
The formula searches for 98 and again cannot find it. This time, it tries to find the next larger value and gets 100, corresponding to grade A:
Tip. When copying an Xlookup formula to multiple cells, lock the lookup or return ranges with absolute cell references (like $B$2:$B$6) to prevent them from changing.
To perform a partial match lookup, set the match_mode argument to 2, which instructs the XLOOKUP function to process the wildcard characters:
To see how it works, please consider the following example. In column A, you have a few smartphone models and, in column B, their battery capacity. You are curious about the battery of a certain smartphone. The problem is that you are not sure you can type the model name exactly as it appears in column A. To overcome this, enter the part that is definitely there and replace the remaining characters with wildcards.
For example, to get information about the battery of iPhone X, use this formula:
=XLOOKUP("*iphone X*", A2:A8, B2:B8, ,2)
Or, input the known part of the lookup value in some cell and concatenate the cell reference with the wildcard characters:
=XLOOKUP("*"&E1&"*", A2:A8, B2:B8, ,2)
In case your table contains several occurrences of the lookup value, you may sometimes need to return the last match. To have it done, configure your Xlookup formula to search in reverse order.
The direction of search is controlled be the 6th argument named search_mode:
As an example, let's return the last sale made by a specific salesperson. For this, we put together the first three required arguments (G1 for lookup_value, B2:B9 for lookup_array, and D2:D9 for return_array) and put -1 in the 5th argument:
=XLOOKUP(G1, B2:B9, D2:D9, , ,-1)
Straightforward and easy, isn't it?
One more amazing feature of XLOOKUP is its ability to return more than one value relating to the same match. All is done with the standard syntax and without any extra manipulations!
From the below table, supposing you want to retrieve all the details pertaining to the salesperson of interest (F2). What you need to do is supply a range, not a singe column or row, for the return_array argument:
=XLOOKUP(F2, A2:A7, B2:D7)
You enter the formula in the top-left cell of the results range, and Excel automatically spills the results into adjacent blank cells. In our case, the return array (B2:D7) includes 3 columns (Date, Item and Amount), and all three values are returned into the range G2:I2.
If you'd rather arrange the results vertically in a column, nest XLOOKUP into the TRANSPOSE function to flip the returned array:
=TRANSPOSE(XLOOKUP(G1, A2:A7, B2:D7))
In a similar fashion, you can return an entire column of data, say the Amount column. For this, use cell F1 that contains "Amount" as lookup_value, the range A1:D1 containing the column headers as lookup_array and the range A2:D7 containing all data as return_array.
=XLOOKUP(F1, A1:D1, A2:D7)
Note. Because multiple values are populated into neighboring cells, make sure you have enough blank cells to the right or down. If Excel cannot find enough empty cells, a #SPILL! error occurs.
Tip. XLOOKUP can not only return multiple entries but also replace them with other values that you specify. A example of such bulk replace can be found here: How to search and replace multiple values with XLOOKUP.
Another big advantage of XLOOKUP is that it handles arrays natively. Due to this ability, you can evaluate multiple criteria directly in the lookup_array argument:
How this formula works: The result of each criteria test is an array of TRUE and FALSE values. The multiplication of the arrays converts TRUE and FALSE into 1 and 0, respectively, and produces the final lookup array. As you know, multiplying by 0 always gives zero, so in the lookup array, only the items that meet all the criteria are represented by 1. And because our lookup value is "1", Excel takes the first "1" in lookup_array (first match) and returns the value from return_array in the same position.
To see the formula in action, let's pull an amount from D2:D10 (return_array) with the following conditions:
With dates in A2:A10 (criteria_range1), salesperson names in B2:B10 (criteria_range2) and items in C2:C10 (criteria_range3), the formula takes this shape:
=XLOOKUP(1, (B2:B10=G1) * (A2:A10=G2) * (C2:C10=G3), D2:D10)
Though the Excel XLOOKUP function processes arrays, it works as a regular formula and is completed with a usual Enter keystroke.
The XLOOKUP formula with multiple criteria is not limited to "equal to" conditions. You are free to use other logical operators as well. For example, to filter orders made on the date in G1 or earlier, put "<=G1" in the first criterion:
=XLOOKUP(1, (A2:A10<=G1) * (B2:B10=G2) * (C2:C10=G3), D2:D10)
To find a value at the intersection of a certain row and column, perform the so-called double lookup or matrix lookup. Yep, Excel XLOOKUP can do that too! You simply nest one function inside another:
How this formula works: The formula is based on XLOOKUP's ability to return an entire row or column. The inner function searches for its lookup value and returns a column or row of related data. That array goes to the outer function as the return_array.
For this example, we are going to find the sales made by a particular salesperson within a certain quarter. For this, we enter the lookup values in H1 (salesperson name) and H2 (quarter), and do a two-way Xlookup with the following formula:
=XLOOKUP(H1, A2:A6, XLOOKUP(H2, B1:E1, B2:E6))
Or the other way round:
=XLOOKUP(H2, B1:E1, XLOOKUP(H1, A2:A6, B2:E6))
Where A2:A6 are the salesperson names, B1:E1 are quarters (column headers), and B2:E6 are data values.
A two-way lookup can also be performed with an INDEX Match formula and in a few other ways. For more information, please see Two-way lookup in Excel.
When the lookup value is not found, Excel XLOOKUP returns an #N/A error. Quite familiar and understandable to expert users, it might be rather confusing for novices. To replace the standard error notation with a user-friendly message, type your own text into the 4th argument named if_not_found.
Back to the very first example discussed in this tutorial. If someone inputs an invalid ocean name in E1, the following formula will explicitly tell them that "No match is found":
=XLOOKUP(E1, A2:A6, B2:B6, "No match is found")
By default, the XLOOKUP function treats lowercase and uppercase letters as the same characters. To make it case-sensitive, use the EXACT function for the lookup_array argument:
How this formula works: The EXACT function compares the lookup value against each value in lookup array and returns TRUE if they are exactly the same including the letter case, FALSE otherwise. This array of logical values goes to the lookup_array argument of XLOOKUP. As the result, XLOOKUP searches for the TRUE value in the above array and returns a match from the return array.
For example, to get the price from B2:B7 (return_array) for the item in E1 (lookup_value), the formula in E2 is:
=XLOOKUP(TRUE, EXACT(E1, A2:A7), B2:B7, "Not found")
Note. If there are two or more exactly the same values in the lookup array (including the letter case), the first found match is returned.
If your formula does not work right or results in error, most likely it's because of the following reasons:
The XLOOKUP function is not backward compatible. It's only available in Excel for Microsoft 365 and Excel 2021, and won't appear in earlier versions.
If your obviously correct Xlookup formula returns a wrong value, chances are that the lookup or return range "shifted" when the formula was copied down or across. To prevent this from happening, be sure to always lock both ranges with absolute cell references (like $A$2:$A$10).
A #VALUE! error occurs if the lookup and return arrays have incompatible dimensions. For instance, it is not possible to search in a horizontal array and return values from a vertical array.
A #REF! error is thrown when looking up between two different workbooks, one of which is closed. To fix the error, simply open both files.
As you have just seen, XLOOKUP has many awesome features that make it THE function for almost any lookup in Excel. I thank you for reading and hope to see you on our blog next week!
Excel XLOOKUP formula examples (.xlsx file)
Table of contents