0
0
Google Sheetsspreadsheet~15 mins

XLOOKUP function in Google Sheets - Deep Dive

Choose your learning style9 modes available
Overview - XLOOKUP function
What is it?
XLOOKUP is a function in Google Sheets that helps you find a value in a list or table and return a matching value from another list or table. It searches for a specific item in a column or row and gives you the related information from the same position in another column or row. This function is easier and more flexible than older lookup functions like VLOOKUP or HLOOKUP. It works both vertically and horizontally and can handle missing values gracefully.
Why it matters
Without XLOOKUP, finding related data in spreadsheets can be slow, error-prone, and limited to specific directions like only vertical or horizontal searches. XLOOKUP solves this by making lookups simpler, more powerful, and less likely to break when you change your data layout. This saves time and reduces mistakes in everyday tasks like tracking expenses, managing inventories, or analyzing data.
Where it fits
Before learning XLOOKUP, you should know basic spreadsheet navigation, how to enter formulas, and simple functions like SUM or IF. After mastering XLOOKUP, you can explore more advanced data analysis tools like FILTER, ARRAYFORMULA, and QUERY to handle complex data tasks.
Mental Model
Core Idea
XLOOKUP finds a value in one list and returns the matching value from another list, working both vertically and horizontally with flexible options.
Think of it like...
Imagine you have a phone book where you look up a person's name and then find their phone number right next to it. XLOOKUP is like that phone book lookup but smarter—it can look left, right, up, or down and even tell you if the name isn't there.
Search List (lookup_array) ──► Match Found? ──► Return Value (return_array)

┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│  Lookup Value │──────▶│  Search Array │──────▶│ Return Array  │
└───────────────┘       └───────────────┘       └───────────────┘
          │                      │                      │
          ▼                      ▼                      ▼
    Value to find          List to search         List to return
Build-Up - 7 Steps
1
FoundationUnderstanding basic lookup concept
🤔
Concept: Learn what a lookup function does: find a value in one list and get related data from another.
Imagine you have a list of fruits and their prices. You want to find the price of 'Apple'. A lookup function searches the fruit list for 'Apple' and returns its price from the price list.
Result
You get the price of 'Apple' when you search for it.
Understanding that lookup functions connect two lists by matching values is the foundation for using XLOOKUP.
2
FoundationBasic XLOOKUP syntax and usage
🤔
Concept: Learn the parts of the XLOOKUP formula and how to write a simple one.
The formula looks like this: =XLOOKUP(search_key, lookup_array, return_array) - search_key: the value you want to find - lookup_array: the list where you search - return_array: the list where you get the result Example: =XLOOKUP("Apple", A2:A10, B2:B10) finds 'Apple' in A2:A10 and returns the matching value from B2:B10.
Result
The formula returns the value related to 'Apple' from the second list.
Knowing the three main parts of XLOOKUP lets you quickly set up lookups without confusion.
3
IntermediateHandling missing values with XLOOKUP
🤔Before reading on: do you think XLOOKUP returns an error or a custom message when it can't find a value? Commit to your answer.
Concept: Learn how to tell XLOOKUP what to do if it doesn't find the search value.
XLOOKUP has an optional fourth argument called 'if_not_found'. You can set it to show a message instead of an error. Example: =XLOOKUP("Banana", A2:A10, B2:B10, "Not found") If 'Banana' is not in A2:A10, it shows 'Not found' instead of an error.
Result
The formula returns 'Not found' if the search value is missing.
Knowing how to handle missing values prevents errors and makes your spreadsheets look cleaner and more user-friendly.
4
IntermediateUsing XLOOKUP for horizontal and vertical lookups
🤔Before reading on: do you think XLOOKUP works only vertically or both vertically and horizontally? Commit to your answer.
Concept: Understand that XLOOKUP can search in rows or columns, making it more flexible than older lookup functions.
XLOOKUP works the same way whether your data is arranged in columns (vertical) or rows (horizontal). Example vertical: =XLOOKUP("Apple", A2:A10, B2:B10) Example horizontal: =XLOOKUP("Q1", B1:E1, B2:E2) This flexibility means you can use one function for many layouts.
Result
You get correct matches whether your data is vertical or horizontal.
Recognizing XLOOKUP's direction flexibility simplifies your formulas and reduces the need for different functions.
5
IntermediateExact and approximate match modes
🤔Before reading on: do you think XLOOKUP defaults to exact match or approximate match? Commit to your answer.
Concept: Learn how to control whether XLOOKUP looks for an exact match or the closest value.
XLOOKUP has a fifth argument called 'match_mode'. It can be: - 0 (default): exact match - -1: exact match or next smaller - 1: exact match or next larger - 2: wildcard match Example: =XLOOKUP(50, A2:A10, B2:B10, "Not found", 1) This finds 50 or the next larger number if 50 isn't found.
Result
You get either an exact match or a close value based on your choice.
Knowing match modes lets you handle data that may not have exact matches, like price ranges or dates.
6
AdvancedUsing XLOOKUP with multiple return columns
🤔Before reading on: do you think XLOOKUP can return multiple columns at once or only one? Commit to your answer.
Concept: Discover how XLOOKUP can return multiple values from several columns in one formula.
Instead of a single return column, you can select multiple columns as the return_array. Example: =XLOOKUP("Apple", A2:A10, B2:D10) This returns all matching values from columns B, C, and D for 'Apple'. The result spills into adjacent cells automatically.
Result
You get multiple related values in one go, filling several cells horizontally or vertically.
Using multiple return columns saves time and keeps related data together without writing many formulas.
7
ExpertXLOOKUP performance and formula optimization
🤔Before reading on: do you think using many XLOOKUPs slows down your sheet significantly? Commit to your answer.
Concept: Understand how XLOOKUP behaves with large data and how to optimize formulas for speed and reliability.
XLOOKUP is efficient but can slow down if used excessively on large datasets. To optimize: - Use exact match mode (0) when possible - Avoid volatile functions inside XLOOKUP - Combine with LET to store repeated calculations - Use array formulas to reduce repeated lookups Example optimization: =LET(found, XLOOKUP("Apple", A2:A1000, B2:B1000), found*2) This stores the lookup result once and reuses it.
Result
Your spreadsheet runs faster and formulas are easier to maintain.
Knowing how to optimize XLOOKUP prevents slow sheets and helps build professional, scalable spreadsheets.
Under the Hood
XLOOKUP works by scanning the lookup_array for the search_key, comparing each item until it finds a match based on the match_mode. Once found, it calculates the relative position of the match and returns the value from the return_array at the same position. Internally, it uses efficient search algorithms optimized for sorted or unsorted data. If no match is found, it returns the if_not_found value or an error.
Why designed this way?
XLOOKUP was designed to replace older lookup functions that were limited to vertical or horizontal searches and often broke when columns or rows were added or removed. It combines flexibility, ease of use, and error handling in one function. The design balances power and simplicity, allowing users to perform complex lookups without complicated formulas.
┌───────────────┐
│ Search Key    │
└──────┬────────┘
       │
       ▼
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│ Lookup Array  │──────▶│ Match Found?  │──────▶│ Return Array  │
└───────────────┘       └──────┬────────┘       └──────┬────────┘
                                │                       │
                                ▼                       ▼
                      Position of match        Value at position
                                │                       │
                                └──────────────┬────────┘
                                               ▼
                                       Returned Value
Myth Busters - 4 Common Misconceptions
Quick: Does XLOOKUP only work vertically like VLOOKUP? Commit yes or no.
Common Belief:XLOOKUP only works vertically, just like VLOOKUP.
Tap to reveal reality
Reality:XLOOKUP works both vertically and horizontally, allowing searches in rows or columns.
Why it matters:Believing it only works vertically limits how you design your spreadsheets and may cause you to use more complicated formulas.
Quick: If XLOOKUP can't find a value, does it always return an error? Commit yes or no.
Common Belief:XLOOKUP always returns an error if the value is not found.
Tap to reveal reality
Reality:XLOOKUP can return a custom message or value if the search value is missing, using the if_not_found argument.
Why it matters:Not knowing this leads to ugly error messages and less user-friendly sheets.
Quick: Does XLOOKUP automatically find approximate matches by default? Commit yes or no.
Common Belief:XLOOKUP defaults to approximate match to find close values.
Tap to reveal reality
Reality:XLOOKUP defaults to exact match; approximate matches must be explicitly requested with the match_mode argument.
Why it matters:Assuming approximate match by default can cause unexpected results and data errors.
Quick: Can XLOOKUP return multiple columns at once? Commit yes or no.
Common Belief:XLOOKUP can only return one value from a single column or row.
Tap to reveal reality
Reality:XLOOKUP can return multiple columns or rows by specifying a range as the return_array, spilling results into adjacent cells.
Why it matters:Missing this feature leads to writing multiple formulas and more complex spreadsheets.
Expert Zone
1
XLOOKUP's match_mode argument supports wildcard characters, enabling flexible text searches beyond exact matches.
2
Using XLOOKUP with dynamic arrays allows automatic spilling of multiple results, which can simplify complex data retrieval tasks.
3
Combining XLOOKUP with LET improves performance by avoiding repeated calculations and makes formulas easier to read and maintain.
When NOT to use
XLOOKUP is not ideal for very large datasets where database queries or specialized tools like QUERY or Apps Script are better. Also, for multi-criteria lookups, FILTER or QUERY functions are more suitable than nesting multiple XLOOKUPs.
Production Patterns
Professionals use XLOOKUP to replace fragile VLOOKUPs, especially in dashboards and reports where data layout changes often. They combine XLOOKUP with IFERROR or custom messages for clean user interfaces. Advanced users embed XLOOKUP inside LET and ARRAYFORMULA for scalable, maintainable spreadsheets.
Connections
Database JOIN operations
XLOOKUP performs a similar role to JOINs by matching keys between tables and returning related data.
Understanding XLOOKUP helps grasp how databases combine tables, bridging spreadsheet and database skills.
Hash maps in programming
XLOOKUP acts like a hash map lookup, finding a key and returning its value efficiently.
Knowing this connection clarifies why XLOOKUP is fast and how lookup functions relate to programming data structures.
Human memory recall
XLOOKUP mimics how we recall information by searching for a cue and retrieving related details.
This analogy helps appreciate lookup functions as tools that automate mental search and retrieval processes.
Common Pitfalls
#1Using XLOOKUP without specifying the if_not_found argument causes ugly errors when values are missing.
Wrong approach:=XLOOKUP("Orange", A2:A10, B2:B10)
Correct approach:=XLOOKUP("Orange", A2:A10, B2:B10, "Not found")
Root cause:Not knowing the optional if_not_found argument leads to unhandled errors in the sheet.
#2Using XLOOKUP with mismatched lookup_array and return_array sizes causes incorrect or spilled results.
Wrong approach:=XLOOKUP("Apple", A2:A10, B2:B5)
Correct approach:=XLOOKUP("Apple", A2:A10, B2:B10)
Root cause:Arrays must be the same size; misunderstanding this causes formula errors or wrong data.
#3Assuming XLOOKUP always finds approximate matches leads to wrong data when exact matches are needed.
Wrong approach:=XLOOKUP(45, A2:A10, B2:B10)
Correct approach:=XLOOKUP(45, A2:A10, B2:B10, "Not found", 0)
Root cause:Not specifying match_mode defaults to exact match, so expecting approximate matches causes confusion.
Key Takeaways
XLOOKUP is a powerful, flexible function that finds a value in one list and returns a matching value from another, working vertically or horizontally.
It improves on older lookup functions by handling missing values gracefully and allowing exact or approximate matches.
You can return multiple columns at once and combine XLOOKUP with other functions for efficient, maintainable spreadsheets.
Understanding XLOOKUP's arguments and behavior prevents common errors and unlocks advanced data retrieval techniques.
XLOOKUP connects spreadsheet lookups to broader concepts like database joins and programming data structures, enriching your overall data skills.