Nested XLOOKUP Function in Google Sheets

Published on

Google Sheets users are well-acquainted with the powerful XLOOKUP function, making the question of whether to use it over other lookup functions less relevant. Now, it’s time to explore advanced techniques, such as Nested XLOOKUP in Google Sheets.

A nested XLOOKUP formula is incredibly versatile. It can retrieve values from multiple tables by searching through them sequentially or even work within a single table.

Syntax:

XLOOKUP(search_key, lookup_range, result_range, [missing_value], [match_mode], [search_mode])

In a nested XLOOKUP in Google Sheets, the second XLOOKUP is typically used in the lookup_range, result_range, or missing_value if only one table is involved. For scenarios involving two tables, the second XLOOKUP is often used to generate the search_key.

Let’s dive into examples to see how it works.

Nested XLOOKUP with One Table

Imagine you’re a birdwatcher maintaining a spreadsheet of your recent encounters with common and rare bird species.

Your data is structured as follows:

  • Column A: Weekday
  • Column B: Bird Name
  • Column C: Number of Views

To find the number of views for “Quail,” you would typically use:

=XLOOKUP("Quail", B2:B, C2:C)

This works if you know that the bird names are in Column B and the results are in Column C. But what if you’re unsure which column contains the search key (bird name)?

Example 1: Replacing lookup_range with a Dynamic Formula

Field labels like “Weekday,” “Bird Name,” and “Number of Views” in the top row (A1:C1) are key. Here’s how you can dynamically find the lookup_range:

=XLOOKUP("Bird Name", A1:C1, A2:C)

This formula searches for the field label “Bird Name” in the top row and returns the corresponding column. Now, replace B2:B in the earlier formula with this dynamic result:

=XLOOKUP("Quail", XLOOKUP("Bird Name", A1:C1, A2:C), C2:C)

If the search keys are in cells E2 and F2, the formula becomes:

=XLOOKUP(F2, XLOOKUP(E2, A1:C1, A2:C), C2:C)
Dynamic Lookup Range in XLOOKUP in Google Sheets

This is a practical example of Nested XLOOKUP in Google Sheets.

Advanced Nested XLOOKUP with Filters

In real-world scenarios, you might need to filter data before applying the nested formula. For instance, to apply the formula only to rows where the weekday is “Monday”:

=LET(range, FILTER(A2:C, A2:A="Monday"), XLOOKUP(F2, XLOOKUP(E2, A1:C1, range), CHOOSECOLS(range, 3)))

Here:

  • FILTER extracts rows for “Monday.”
  • LET assigns a name (“range”) to this filtered data.
  • CHOOSECOLS selects the required column (third).

Example 2: Replacing result_range with a Dynamic Formula

For a dataset where Column A contains employee names and Columns B to D represent monthly sales leads, here’s how to find Jennifer’s February sales dynamically:

=XLOOKUP(G2, A2:A, XLOOKUP(H2, A1:E1, A2:E))
Dynamic Result Range in XLOOKUP in Google Sheets

Here:

  • G2 contains the name “Jennifer.”
  • H2 specifies the month “Feb.”
  • The inner XLOOKUP dynamically determines the column for “Feb.”

Example 3: Replacing missing_value with a Nested XLOOKUP

A truly nested XLOOKUP in Google Sheets can handle missing values by chaining multiple XLOOKUP functions. For example:

=XLOOKUP("Orange", A2:A, B2:B, XLOOKUP("Orange", C2:C, D2:D, XLOOKUP("Orange", E2:E, F2:F)))

This formula searches “Orange” in three lookup-result pairs sequentially, stopping at the first match.

Nested XLOOKUP in Google Sheets Using the Missing Value Argument

Nested XLOOKUP with Two Tables

For scenarios with multiple tables, one XLOOKUP can generate the search_key for another.

Example 1: Replacing search_key with XLOOKUP

Suppose you have two tables, “emp data” and “salary,” with “ID” as the common field. To find the gross salary of “Ben” using his name:

=XLOOKUP(XLOOKUP("Ben", 'emp data'!B2:B, 'emp data'!A2:A), salary!A2:A, salary!C2:C)
Nested XLOOKUP with Two Tables in Google Sheets

Here:

  • The inner XLOOKUP retrieves Ben’s ID from the “emp data” table.
  • The outer XLOOKUP uses the ID to fetch Ben’s salary from the “salary” table.

Conclusion

The Nested XLOOKUP in Google Sheets is a robust tool for solving complex lookup scenarios. Whether you’re working within a single table or across multiple tables, mastering this function will elevate your Google Sheets expertise.

Resources

Explore these resources to deepen your understanding of XLOOKUP’s capabilities!

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

Reservation and Booking Status Calendar Template in Google Sheets

My reservation and booking status calendar template in Google Sheets uses spreadsheet cells as rooms and highlighting to show availability/non-availability. I have used a few...
Multi Row Dynamic Dependent Drop-Down List in Google Sheets

Multi-Row Dynamic Dependent Drop-Down List in Google Sheets

We can create a multi-row dynamic dependent drop-down list in Google Sheets without using Google Apps Script. This tutorial explains how. I will only use...

Date-Related Conditional Formatting Rules in Google Sheets

Based on my experience, much of the conditional formatting in Google Sheets centers around dates. Therefore, in this tutorial, I've included several date-related conditional...
Populate info in Spreadsheet

Auto-Populate Information Based on Drop-down Selection in Google Sheets

Another awesome Google Sheets tutorial! This time, we'll learn how to auto-populate information based on a drop-down selection. Spreadsheet applications are always enticing to me....
USAGE OF DATE IN QUERY SYNTAX

How to Use Date Criteria in Query Function in Google Sheets [Date in Where...

Using dates as the criteria are a complicated part of any criteria formation in the Google Sheet functions. In most cases, you can not...

More like this

Rental Property Manager Template for Google Sheets (Free & Fully Automated)

Do you want to manage all aspects of your rental properties, such as tracking...

Content Calendar Template in Google Sheets (Free, Dynamic & Fully Automated)

Are you a content creator managing posts across multiple platforms — Blogs, YouTube, Twitter...

Funnel Chart in Google Sheets (Dynamic without Helper Columns)

Most tutorials online create a funnel chart in Google Sheets using a stacked bar...

LEAVE A REPLY

This site uses Akismet to reduce spam. Learn how your comment data is processed.