Sub topic 13
Choosing between VLOOKUP and XLOOKUP
This chapter assumes you can enter formulas in Google Sheets, read ranges such as A2:C100, anchor ranges with $, and point a formula at another sheet. It also assumes you have met both functions in the earlier chapters. Here you will compare them on the same tasks and build a rule for choosing one.
The short answer
Use XLOOKUP for new work in Google Sheets. It is harder to break, it can look left, and it has a built-in "not found" argument. Use VLOOKUP when you are maintaining a sheet that already uses it and works, or when the file must also open in a spreadsheet program that lacks XLOOKUP.
The rest of the chapter explains the reasons, so you can judge the exceptions yourself.
How the two signatures differ
Both functions find a key in one column and return a value from the same row. They differ in how you say which value to return.
=VLOOKUP(search_key, range, index, [is_sorted])
=XLOOKUP(search_key, lookup_range, result_range, [missing_value], [match_mode], [search_mode])VLOOKUP takes one rectangular range. It searches the first column of that range and returns the value from the column whose position number you give as index. XLOOKUP takes two separate ranges, one to search and one to return from.
This one design difference causes most of the practical differences below.
| Feature | VLOOKUP | XLOOKUP |
|---|---|---|
| Where the result comes from | Column number counted inside `range` | A separate `result_range` |
| Default match | Approximate (`is_sorted` defaults to TRUE) | Exact |
| Lookup to the left of the result | Not possible directly | Yes |
| Missing key | `#N/A` unless wrapped in IFNA | Optional `missing_value` argument |
| Nearest-value matching | Only "next smaller", and the data must be sorted | Next smaller or next larger, in any order |
| Wildcards | Work in exact mode | Need match mode 2 |
| Last match instead of first | Not possible directly | Search mode -1 |
| Several columns at once | One formula per column | One formula, wide `result_range` |
Where each function fails
VLOOKUP: the silent failures
VLOOKUP has two failure modes that return a wrong answer instead of an error. Wrong answers are worse than errors, because nothing tells you to check.
The first is the default match mode. If you leave out the last argument, VLOOKUP assumes the first column is sorted and uses approximate matching. On unsorted data it can return a value from the wrong row, without any error. Always write FALSE unless you want approximate matching.
=VLOOKUP(E2, A2:C100, 3, FALSE)The second is the hard-coded column index. The 3 in the formula above means "the third column of the range". If someone inserts a new column between B and C in the sheet, the formula can end up returning a different column's data. It keeps running and shows plausible values from the wrong column. A new column added before the range start changes the range references, but the index number is not adjusted to compensate for what you intended.
XLOOKUP: fewer silent failures
XLOOKUP defaults to exact matching, so a forgotten argument does not change the result. Its result range is a real reference, so Sheets adjusts it when columns move or are inserted.
=XLOOKUP(E2, A2:A100, C2:C100, "Not found")XLOOKUP still has its own pitfalls:
- The lookup range and the result range must have matching sizes in the search direction. If
A2:A100is paired withC2:C50, the formula returns an error, so keep the row counts equal. - Using the wrong match mode number returns a plausible but wrong row. Mode
-1means "exact or next smaller", and mode1means "exact or next larger". Mixing them up is easy. - Wildcards are off by default. A key such as
"Wid*"is treated as literal text unless you set match mode2.
Decision criteria
Work through these questions in order. The first one that applies usually decides the choice.
Compatibility
Older versions of Excel, such as Excel 2019 and earlier, do not have XLOOKUP. If you export a Sheets file and a colleague opens it in one of those versions, XLOOKUP cells show errors. VLOOKUP works almost everywhere. If your audience is only people using Google Sheets, this concern disappears.
Direction and position
If the key is to the right of the value you need, VLOOKUP cannot do it directly, because it only returns columns to the right of the key. XLOOKUP does it with no workaround:
=XLOOKUP(E2, C2:C100, A2:A100, "Not found")The common VLOOKUP workaround is to rearrange the columns or build a helper column. Neither is needed with XLOOKUP.
First match versus last match
When a key appears several times, both functions return the first match by default. To get the last one, such as the most recent order for a customer in a log sorted by date, XLOOKUP's search mode -1 searches from the bottom up:
=XLOOKUP(E2, A2:A100, C2:C100, "Not found", 0, -1)VLOOKUP has no equivalent. You would need a different function pattern entirely.
Tiers and thresholds
Tier tables, such as commission rates or shipping bands, use approximate matching. Both functions can do it, but the requirements differ.
=VLOOKUP(B2, $F$2:$G$6, 2, TRUE)
=XLOOKUP(B2, $F$2:$F$6, $G$2:$G$6, "Below minimum", -1)The VLOOKUP version needs the tier table sorted ascending by its first column, and it returns #N/A for a value below the first tier. The XLOOKUP version does not need sorting, and it lets you choose what to show for values below the lowest tier. XLOOKUP with 1 instead of -1 rounds up to the next larger tier, a case VLOOKUP cannot handle.
Multiple columns
If you need several columns for the same row, XLOOKUP can return them from one formula with a wide result range:
=XLOOKUP(E2, A2:A100, B2:D100)With VLOOKUP, you would write three formulas with indexes 2, 3 and 4, or combine it with other functions. One XLOOKUP formula is easier to maintain, and it performs one search instead of three.
Missing keys
XLOOKUP handles a missing key itself:
=XLOOKUP(E2, A2:A100, C2:C100, "Not found")VLOOKUP needs a wrapper:
=IFNA(VLOOKUP(E2, A2:C100, 3, FALSE), "Not found")Use IFNA rather than IFERROR with either function. IFERROR hides every error, including a mistyped range or an invalid index, and those are errors you want to see. IFNA only replaces #N/A, which is the "key not found" signal.
Working with many keys and other sheets
Both functions work across sheets. You put the sheet name before the range:
=XLOOKUP(A2, Products!A:A, Products!C:C, "Not found")Whole-column references such as Products!A:A are convenient, because new rows are included automatically. On a very large sheet, bounded ranges such as Products!A2:A5000 can recalculate faster. For a sheet that keeps growing, the whole-column form is usually worth the small cost.
To apply VLOOKUP to a whole column of keys, wrap it in ARRAYFORMULA so a single formula fills the results downward:
=ARRAYFORMULA(VLOOKUP(A2:A20, Products!A2:C100, 3, FALSE))A single array formula has one advantage over copied formulas. You cannot leave a gap or overwrite one cell by accident, and the output range stays consistent. Its disadvantage is that if anything in the way blocks the output range, the formula returns a #REF! error until you clear the blocking cells.
Troubleshooting is the same for both
When either function returns #N/A for a key you can see in the data, the cause is usually one of these:
- A hidden leading or trailing space. Wrap the key in
TRIM, for example=VLOOKUP(TRIM(A2), Products!A2:C100, 3, FALSE). If the space is in the lookup column instead, clean that column. - A number stored as text in one place and a real number in the other. Both look identical, but they do not match. Convert one side so the types agree.
- Approximate matching on unsorted data in VLOOKUP, which either returns the wrong row or
#N/A. Set the last argument toFALSE. - A mismatch in range sizes in XLOOKUP, or an index larger than the number of columns in VLOOKUP.
None of these is a reason to prefer one function. They do mean you should check your data before blaming the formula.
A practical migration rule
You do not need to rewrite working VLOOKUP formulas. A rewrite costs time and can introduce mistakes, and the old formula still works. Consider converting one when:
- someone is about to insert columns into the table it reads from,
- you need to add a left lookup, last match, or several return columns, or
- the formula uses approximate matching on a table that could become unsorted.
When you convert, check the result against the old formula on several keys, including one that does not exist and one that appears twice.
Exercise
A sheet has product IDs in column C and product names in column A. You need the name for the ID in E2, and you want the text "Unknown ID" if the ID is missing. Which function would you choose, and what is the formula for rows 2 to 100?
Show answer
Use XLOOKUP, because the name is to the left of the ID and VLOOKUP cannot return a column to the left of its search column. The formula is =XLOOKUP(E2, C2:C100, A2:A100, "Unknown ID"). The fourth argument supplies the text for a missing key, so no IFNA wrapper is needed.
Exercise
A colleague's formula =VLOOKUP(B2, $F$2:$G$6, 2) returns correct tiers for most rows, but after someone re-sorted the tier table by name, some rows show the wrong tier and no error. Explain what happened and give two ways to fix it.
Show answer
With the last argument omitted, VLOOKUP uses approximate matching, which assumes the first column is sorted ascending. After the table was re-sorted, that assumption broke, so VLOOKUP returned values from the wrong rows without raising an error. One fix is to sort the tier table ascending by its first column again. The other is to use =XLOOKUP(B2, $F$2:$F$6, $G$2:$G$6, "Below minimum", -1), which does not require sorting.