Home >Software Tutorial >Office Software >Forget VLOOKUP in Excel: Here's Why I Use XLOOKUP
As a long-term Excel enthusiast, I have always enjoyed using VLOOKUP, one of Excel's best-known lookup functions. However, Microsoft's introduction of XLOOKUP in 2019 changed everything. Once I realized how useful XLOOKUP is, I knew I'd never look back.
I'll use direct cell references to exemplify my points in this article, as they are clearer than structured references. I also won't talk explicitly about HLOOKUP because—other than its direction—it works in exactly the same way as VLOOKUP.
Before I explain why I prefer XLOOKUP to VLOOKUP, I'll show you how they work.
XLOOKUP has six arguments:
=XLOOKUP(<em>a</em>,<em>b</em>,<em>c</em>,<em>d</em>,<em>e</em>,<em>f</em>)
where
In this example, I want Excel to look up the employee ID based on the name in cell H1, and return the result to cell H2.
To do this, I will type the following formula into cell H2:
=XLOOKUP(<em>a</em>,<em>b</em>,<em>c</em>,<em>d</em>,<em>e</em>,<em>f</em>)
In this case, cell H1 contains the value Excel needs to look up (Mary), B2 to B12 is where that value can be found (employees' names), A2 to A12 is where the corresponding result will be pulled from (employees' IDs), and "Invalid name" is what I want Excel to return if the lookup value isn't anywhere to be found in the lookup array.
I've gone for the default values for arguments e and f because I want an exact match, and I want Excel to search from the top of the lookup array (more on these later).
Here's the VLOOKUP syntax, which has four arguments:
=XLOOKUP(H1,B2:B12,A2:A12,"Invalid name",0,1)
where
In this example, I want Excel to look up the nationality based on the employee ID in cell H4, and return the result to cell H5.
To do this, in cell H5, I will type
=XLOOKUP(<em>a</em>,<em>b</em>,<em>c</em>,<em>d</em>,<em>e</em>,<em>f</em>)
because cell H4 contains the lookup value (ID 3264), cells A2 to E12 are where Excel needs to find that value and the corresponding return, the fifth column (the country) is the array in which the result will be found, and I want an exact match (FALSE).
One key difference between VLOOKUP and XLOOKUP is that the former requires me to specify a column index number where the result will be found, whereas the latter doesn't. This is because VLOOKUP combines the lookup and return arrays into one argument, whereas XLOOKUP defines them in two separate arguments.
Having to specify the column index number in VLOOKUP can lead to several issues:
On the other hand, XLOOKUP contains the lookup array as a separate argument, meaning you can appreciate the following benefits:
Both VLOOKUP and XLOOKUP can return an exact match (the exact corresponding value in a row) and an approximate match (a nearby corresponding value).
More specifically, VLOOKUP's approximate match (indicated by TRUE in the formula) searches down the lookup array until it finds a value that's larger than the lookup value. It then returns the value that is one row up from there.
Take Student D's score of 65 in the example below. VLOOKUP takes the lookup value of 65, reviews the lookup array, finds the first value that's larger than the lookup value (in this case, 70), and then returns the grade from the row above (grade C).
This presents two drawbacks. First, the lookup array must be listed in ascending order. Second, I have to add a FAIL row to the lookup array, as I don't have the option in VLOOKUP to state a non-matching argument.
On the other hand, XLOOKUP offers three alternatives to VLOOKUP's one-dimensional approximate match:
Again, take Student D as an example. With a score of 65, Excel will see that the next smallest value in the lookup array is 60, and the next largest value is 70. Since the student hasn't yet reached the threshold for grade B (70), I need Excel to take the next smallest value in the lookup array (60) to return grade C from the return array. So, I will type -1 as the matching option in the formula.
This means that the lookup array doesn't have to be in order—Excel scours the whole lookup array to find the nearest higher or lower values if there's not an exact match. I can also omit the FAIL row from my lookup array because if a student's score does not match any grades, I can use the fourth argument in the XLOOKUP syntax to return the word FAIL.
While VLOOKUP searches from first to last, returning the first matching value, XLOOKUP offers four search options.
In most lookup scenarios, searching the lookup array from first to last will return the results you need. For example, if you have a directory of phone numbers and people's names, using VLOOKUP to find the phone number based on the name you input will work just fine, as that person's name is only likely to appear once.
However, XLOOKUP lets you choose the search orientation:
The benefit of a last-to-first lookup is that you can find the most recent occurrence of a value in a lookup array that is listed in date order. To achieve this with VLOOKUP, you would have to reverse the order of the data first.
A really useful feature of XLOOKUP is the "if not found argument," which VLOOKUP doesn't have.
If a value is not found in an exact match VLOOKUP formula, Excel returns the dreaded #N/A error message. To fix this, I've always embedded VLOOKUP functions within the IFERROR function so that I can define the output if VLOOKUP doesn't find a match.
=XLOOKUP(<em>a</em>,<em>b</em>,<em>c</em>,<em>d</em>,<em>e</em>,<em>f</em>)
While this is a reasonable solution, it makes formula writing much more complex and can hide issues that might affect the accuracy of your data analysis.
Since XLOOKUP comes ready-made with an "if not found" argument, you can define what happens if the value does not appear in the lookup, saving you from having to embed the formula within IFERROR.
One of VLOOKUP's most stubborn properties is that it can only return a single match, whereas XLOOKUP can return a range.
In this example, typing
=XLOOKUP(H1,B2:B12,A2:A12,"Invalid name",0,1)
looks up the value in cell I1 (in this case, Quizpicable Me), looks for that value in cells A2 to A7, and returns all the corresponding values as a spilled array.
If I were to try to replicate this using VLOOKUP, I would type
=VLOOKUP(<em>a</em>,<em>b</em>,<em>c</em>,<em>d</em>)
but this returns a #REF! error because the third argument (column index number) can only be a single digit, not a range. This means that XLOOKUP is much more adaptable, as it can return either a single value or a range, depending on the parameters you add to the formula.
Since pre-2019 versions of Excel don't support XLOOKUP, don't discard VLOOKUP and HLOOKUP altogether! There may still be cases when you need to use them, like if you're sending a spreadsheet to someone who hasn't upgraded their Office package for a few years.
The above is the detailed content of Forget VLOOKUP in Excel: Here's Why I Use XLOOKUP. For more information, please follow other related articles on the PHP Chinese website!