Google Sheets XLOOKUP Match Mode: Practical Guide

Learn how to use Google Sheets XLOOKUP match mode to find exact, nearest, or wildcard matches with practical, step-by-step examples for students and professionals.

How To Sheets
How To Sheets Team
·5 min read
XLOOKUP Match Mode - How To Sheets
Photo by magocarlosyovia Pixabay
Quick AnswerDefinition

Google Sheets XLOOKUP match mode extends the standard XLOOKUP function by letting you specify how values should be matched. With match_mode, you can demand an exact match, accept the nearest smaller or larger value, or use wildcard patterns. When combined with optional search_mode, you can control the direction of the lookup. This approach mirrors Excel’s capabilities and unlocks robust, flexible lookups in Google Sheets for real-world data tasks. master these tricks to build resilient sheets for students, professionals, and business owners.

What is XLOOKUP and match_mode in Google Sheets

Google Sheets supports XLOOKUP as a flexible replacement for traditional lookups. The match_mode parameter controls how the function interprets the lookup_key against the lookup_array. Available modes include 0 for exact matches, -1 for exact matches or next smaller values, 1 for exact matches or next larger values, and 2 for wildcard matching. When you combine match_mode with search_mode, you can decide whether the lookup searches from top to bottom or bottom to top. This combination makes XLOOKUP particularly powerful for datasets with gaps, inconsistencies, or patterns. In this guide we focus on how to use google sheets xlookup match mode effectively, with practical examples you can adapt in your own sheets. The goal is to give you a solid mental model and robust formulas you can reuse in real-world projects.

Exact-match example: straightforward lookups

Exact matching is the most common scenario when keys are unique and the data is well-structured. In Google Sheets, you provide the lookup_key, a lookup_array, and a return_array. The optional if_not_found argument helps keep your sheet clean when there is no match. Finally, the match_mode argument is set to 0 to require an exact match. This setup is ideal for inventory SKUs, student IDs, or any dataset where a precise key exists. Below is a minimal, copy-pasteable example that you can test in your own sheet.

Excel Formula
=XLOOKUP(A2, A2:A10, B2:B10, "Not found", 0)
  • A2: lookup key in the left column
  • A2:A10: lookup_array where to search
  • B2:B10: return_array with corresponding results
  • "Not found": fallback if no match
  • 0: exact match only

If you prefer a named range, you can replace A2:A10 with a named range like Keys and Returns with ReturnCol.

Nearest-match examples: -1 and 1

In cases where the exact key might be missing, match_mode -1 or 1 helps you retrieve the nearest value either below or above the search key. This is especially useful in pricing tiers or grade thresholds where an exact row may not exist. Sorting the lookup_array is important for predictable results. We’ll show two formulas side-by-side and explain the behavior.

Excel Formula
=XLOOKUP(A2, A2:A10, B2:B10, "Not found", -1)
=XLOOKUP(A2, A2:A10, B2:B10, "Not found", 1)
  • -1: exact match or next smaller value (requires the lookup_range to be sorted ascending for predictable results)
  • 1: exact match or next larger value (same sorting caveat)

If your data isn’t sorted, consider wrapping XLOOKUP with a sort or using an alternative approach to guarantee deterministic results.

Wildcard matching: using match_mode 2

Wildcard matching allows flexible lookups when keys follow patterns rather than exact values. Use * to represent any number of characters and ? for a single character. This is handy for names, codes, or product catalogs with consistent prefixes or suffixes. Note that wildcard searches are text-based, so numeric fields won’t respond to wildcards in the same way. The example below demonstrates a common pattern.

Excel Formula
=XLOOKUP("Jo*", A2:A10, B2:B10, "Not found", 2)
  • "Jo*": wildcard pattern for names starting with Jo
  • match_mode 2: enables wildcard matching

Tip: When using wildcards, ensure data is text; numeric data will not match as expected.

Practical tips and pitfalls

This section covers best practices and common mistakes as you work with XLOOKUP match mode in Google Sheets. Use IFNA or IFERROR to handle missing values gracefully so end users don’t see #N/A or #VALUE errors. For example:

Excel Formula
=IFNA(XLOOKUP(A2, A2:A10, B2:B10, "Not found", 0), "N/A")

Be mindful of data sorting when using -1 or 1; the nearest-match behavior depends on the sort order of the lookup_array. If duplicates exist, XLOOKUP will return the first match it encounters unless you implement a different lookup strategy. For large datasets, consider limiting the lookup range to improve performance and maintainability.

Advanced variants: named ranges and performance tips

Leverage named ranges to simplify formulas and readability. For instance, define Keys for A2:A10 and Values for B2:B10, then rewrite the formula as a cleaner reference:

Excel Formula
=XLOOKUP(D2, Keys, Values, "Missing", 0)

If your data changes frequently, caching results with volatile functions can help—but be cautious about staleness. You can also combine XLOOKUP with other logic, such as IF, ISNA, or FILTER, to build robust data pipelines in sheets that act as lightweight databases.

Steps

Estimated time: 15-25 minutes

  1. 1

    Prepare dataset

    Organize your data into a lookup column and a corresponding return column. Ensure keys are consistent and free of leading/trailing spaces to enable reliable XLOOKUP usage with match_mode.

    Tip: Trim whitespace to prevent subtle mismatches.
  2. 2

    Build an exact-match formula

    Write an XLOOKUP with match_mode 0 to retrieve exact matches. Start by selecting the lookup key cell and your lookup/return arrays, then test with a known key.

    Tip: Test with a known key to confirm correct mapping.
  3. 3

    Try nearest matches

    Experiment with match_mode -1 and 1 on sorted data to fetch the nearest value below or above the key. Review the impact of data order on results.

    Tip: Sort the lookup array to ensure deterministic outcomes.
  4. 4

    Enable wildcard lookups

    Use match_mode 2 with a wildcard pattern like Jo* to capture variations. Verify results across multiple sample keys.

    Tip: Limit wildcard usage to patterns you can predict.
  5. 5

    Handle missing values gracefully

    Wrap XLOOKUP with IFNA/IFERROR to display a friendly message when no match is found.

    Tip: Avoid #N/A in end-user reports.
Pro Tip: Named ranges simplify maintenance and readability of XLOOKUP formulas.
Warning: Nearest-match modes (-1, 1) require careful data sorting for deterministic results.
Note: Wildcard matching is powerful but can yield multiple matches if not restricted.

Prerequisites

Required

  • Google Sheets (web) in a modern browser
    Required
  • A dataset with a lookup column and a return column
    Required

Optional

  • Basic familiarity with formulas (VLOOKUP, INDEX/MATCH)
    Optional
  • Optional: Named ranges to simplify references
    Optional

Keyboard Shortcuts

ActionShortcut
Copy formulaEditing a cellCtrl+C
Paste formulaInsert into destination cellCtrl+V
Fill downPropagate formula to adjacent cellsCtrl+D
Find in sheetQuick search within the sheetCtrl+F
Save workbookPreserve changesCtrl+S

FAQ

What is XLOOKUP match mode in Google Sheets?

XLOOKUP match mode controls how the lookup matches the search key. It supports exact matches (0), nearest smaller (-1), nearest larger (1), and wildcard patterns (2).

XLOOKUP match mode defines how the lookup matches the key, including exact matches, nearest values, or wildcard patterns.

Can I use XLOOKUP match mode with unsorted data?

Nearest-match modes require careful consideration of sort order. When using -1 or 1, ensure the lookup array is sorted in ascending order for reliable results.

Nearest-match modes work best with sorted data; unsorted data may give unpredictable results.

What happens if no match is found?

If the lookup key isn't found and no exact match exists, XLOOKUP returns the optional if_not_found value or an error, depending on how you configure it.

If there’s no match, you’ll get the not-found value or an error unless you handle it with IFNA or IFERROR.

How does wildcard matching work?

Wildcard mode (2) supports * and ?. It returns the first match that fits the pattern in the lookup array. Ensure your data is text.

Wildcard mode lets you use patterns like Jo* to match several names.

Is XLOOKUP available in Google Sheets?

Yes. Google Sheets supports XLOOKUP with match_mode and search_mode to enable flexible lookups.

Yes, XLOOKUP is available in Google Sheets with flexible matching options.

How can I optimize performance for large sheets?

Limit lookup ranges, avoid volatile formulas, and consider using named ranges or caching results if you perform many lookups.

Limit ranges and reuse results to keep sheets fast.

The Essentials

  • Use match_mode 0 for exact lookups
  • Employ -1 or 1 for nearest matches when data is sorted
  • Leverage wildcard match_mode 2 for pattern-based lookups
  • Wrap with IFNA/IFERROR to handle missing results gracefully

Related Articles