Google Sheets XLOOKUP Syntax: A How-To Guide
In this article
XLOOKUP in Google Sheets finds a value in one range and returns the matching value from another range, and its syntax is =XLOOKUP(search_key, lookup_range, result_range, [missing_value], [match_mode], [search_mode]). The first three arguments are required; the last three are optional and control what happens when no match is found, whether matching is exact or approximate, and which direction the search runs. Unlike VLOOKUP, XLOOKUP does not care whether your lookup column sits to the left or right of the result column, which is why it is the safer default for most lookups.
What You'll Need
- A Google account with access to Google Sheets (the function is built in; no add-on is required).
- A spreadsheet with at least two ranges: one containing the values you will search for, and one containing the values you want returned.
- The two ranges should have the same number of rows (or columns, if you are searching horizontally). Mismatched sizes are the most common cause of wrong results.
- Basic familiarity with cell references and absolute references (the
$sign).
Step-by-Step
- Open your sheet and click the cell where the result should appear. This is where the returned value will be written. It can be on the same sheet or a different one.
- Type
=XLOOKUP(to start the formula. Google Sheets will show a tooltip listing the arguments in order. Argument labels and tooltip wording can differ slightly by version and region, but the order is stable. - Enter the search key. This is the value you are looking for. It can be a literal value like
"Widget A", a number, or a cell reference such asA2. For a formula you will copy down a column, use a relative reference likeA2so it shifts per row. - Enter the lookup range. This is the single row or column that contains the values to match against. For example,
Products!A2:A100. Use absolute references ($A$2:$A$100) if you plan to copy the formula, so the range does not drift. - Enter the result range. This is the row or column containing the values you want returned, for example
Products!C2:C100. It must be the same size as the lookup range. XLOOKUP returns the value at the same relative position in this range as the match found in the lookup range. - Add the optional missing_value argument if you want a custom fallback. Type a comma, then the value to return when no match is found, for example
"Not found"or0. If you omit this argument, XLOOKUP returns#N/Awhen there is no match. - Add the optional match_mode argument. Use
0for exact match (the default),-1for exact match or the next smaller item,1for exact match or the next larger item, or2for a wildcard match. Most lookups should use0. - Add the optional search_mode argument. Use
1to search from the first entry to the last (the default),-1to search from last to first,2for a binary search on data sorted ascending, or-2for a binary search on data sorted descending. If you are unsure, leave it out. - Close the parenthesis and press Enter. The result appears in the cell. If you see an error, check the range sizes first.
- Copy the formula down or across as needed. Confirm that relative and absolute references behave as intended. A quick way to check is to click a copied cell and verify the ranges still point where you expect.
Common Mistakes
- Mismatched range sizes. If the lookup range has 99 rows and the result range has 100, XLOOKUP may return the wrong row or an error. Both ranges must be the same height (or width for horizontal lookups).
- Forgetting absolute references when copying. Without
$signs, the lookup and result ranges shift as you drag the formula, producing wrong matches or#REF!errors. - Using approximate match by accident. Leaving match_mode at
1or-1on unsorted data can return a nearby value instead of the exact one. Use0unless you specifically need approximate matching. - Searching a range that includes headers. If the lookup range starts at row 1 and row 1 is a header, the header text can be matched unintentionally. Start ranges at the first data row.
- Assuming XLOOKUP works like VLOOKUP with column indexes. XLOOKUP takes a result range, not a column number. Passing a number where a range is expected produces an error.
- Mixing data types. A number stored as text (for example,
"123") will not match a numeric123. Check formatting if a match that should exist returns the missing value.
Tips
- Use the missing_value argument to keep reports clean; a blank or a short label reads better than a column of
#N/A. - Name your ranges (Data > Named ranges) so formulas read like
=XLOOKUP(A2, ProductIDs, Prices, "Not found"). Named ranges also survive row insertions better than raw references. - For two-way lookups, nest XLOOKUP: use one XLOOKUP to find the row and another to find the column, then combine with INDEX. This is more readable than a large nested IF.
- If you need to return multiple adjacent columns, XLOOKUP can return a whole row or column from the result range when the result range is wider than one column; spill behavior depends on the sheet's current calculation settings.
- Test with a value you know exists and one you know does not, so you can see both the match and the fallback behavior before relying on the formula.
- Keep lookup columns free of leading or trailing spaces;
TRIMthe source data if imports are involved.
Troubleshooting
If XLOOKUP returns #N/A, first confirm the search key exists in the lookup range and that both are the same data type. Next, check for hidden spaces or non-printing characters. If the formula returns a value from the wrong row, compare the row counts of the two ranges and look for a shifted start row. If you see #REF!, a referenced sheet or range may have been deleted or moved; re-enter the range. If you see #VALUE!, an argument is the wrong type, often a number where a range is expected. If the formula worked yesterday and fails today, check whether rows were inserted above the ranges; absolute references usually survive, relative ones do not. Finally, confirm the formula is in a cell that is not formatted as text; a leading apostrophe turns the formula into a literal string.
Frequently Asked Questions
Is XLOOKUP available in all Google Sheets accounts?
Yes. XLOOKUP is a built-in Google Sheets function and does not require an add-on or a specific plan. If you do not see it, check that you are in Google Sheets rather than a different spreadsheet app.
What is the difference between XLOOKUP and VLOOKUP?
VLOOKUP searches only to the right of the lookup column and uses a column index number. XLOOKUP accepts separate lookup and result ranges, so it can return values from either side, and it handles missing values and match modes more explicitly.
Can XLOOKUP search horizontally?
Yes. Use a single-row lookup range and a single-row result range, and the function matches across columns instead of down rows. The two ranges must still be the same size.
Why does XLOOKUP return the wrong match when duplicates exist?
By default it returns the first match found. Set search_mode to -1 to search from the last entry backward and return the last match instead.
Does XLOOKUP work across different sheets or files?
It works across sheets in the same spreadsheet using references like Sheet2!A2:A100. Across separate files, use IMPORTRANGE first to bring the data into the current file, then run XLOOKUP on the imported range.
What happens if the lookup range and result range are different sizes?
Google Sheets may return an error or an unexpected result. Always verify both ranges cover the same number of rows or columns before trusting the output.