Two-Way Lookup with XLOOKUP in Google Sheets

Published on

When you need to look up one search key vertically and another horizontally, you can rely on XLOOKUP in Google Sheets. The key to performing a two-way lookup with XLOOKUP is replacing the result range of one XLOOKUP with another XLOOKUP.

Generic Formulas

=XLOOKUP("Tuesday", column, XLOOKUP("Period 3", row, data))

Where column and row are the lookup column and row (usually the first column and row of a table), and data is the entire table range. ‘Tuesday’ is the vertical search key, and ‘Period 3’ is the horizontal search key.

Alternatively, you can use:

=XLOOKUP("Period 3", row, XLOOKUP("Tuesday", column, data))

Both formulas will return the same result.

Example of Two-Way Lookup with XLOOKUP in Google Sheets

Assume a school schedule is stored in the range A1:G6, where column A lists weekdays, row 1 contains period names, and the grid (B2:G6) holds the assigned subjects and teachers.

Here’s how to look up the subject and teacher assigned to a specific period on a specific weekday:

=XLOOKUP("Tuesday", A1:A6, XLOOKUP("Period 3", B1:G1, B1:G6))
Example of Two-Way XLOOKUP in Google Sheets for Vertical and Horizontal Lookup

The inner XLOOKUP searches for “Period 3” in B1:G1 and returns the corresponding column (e.g., column D1:D6).

Period 3
Science (Mr. Brown)
Social Studies (Ms. Davis)
English (Ms. Johnson)
English (Ms. Johnson)
Math (Mr. Smith)

The outer XLOOKUP then searches for “Tuesday” in A1:A6 and returns the corresponding value from D1:D6.

Alternatively, you can switch the lookup order:

=XLOOKUP("Period 3", A1:G1, XLOOKUP("Tuesday", A1:A6, A1:G6))

Here, the inner XLOOKUP searches for “Tuesday” in A1:A6 and returns the corresponding row (e.g., row 3: A3:G3).

TuesdayEnglish (Ms. Johnson)Math (Mr. Smith)Social Studies (Ms. Davis)Science (Mr. Brown)Music (Mr. Wilson)PE (Mr. Lee)

The outer XLOOKUP then searches for “Period 3” in A1:G1 and returns the corresponding value from A3:G3.

Advantages of Two-Way Lookup with XLOOKUP in Google Sheets

One advantage of this approach is its simplicity. The function is easy to understand since it simply replaces the result range of one XLOOKUP with another XLOOKUP. Another benefit is that you can use wildcard matching by setting match mode 2 in XLOOKUP.

A key advantage of two-way lookup with XLOOKUP is that the result can act as a reference. This means you can use it with OFFSET to look around that value. For example:

=OFFSET(XLOOKUP("Tuesday", A1:A6, XLOOKUP("Period 3", B1:G1, B1:G6)), 0, -1)  "Returns the previous period"
=OFFSET(XLOOKUP("Tuesday", A1:A6, XLOOKUP("Period 3", B1:G1, B1:G6)), 0, 1)  "Returns the next period"
=OFFSET(XLOOKUP("Tuesday", A1:A6, XLOOKUP("Period 3", B1:G1, B1:G6)), -1, 0) "Same period on the previous day"
=OFFSET(XLOOKUP("Tuesday", A1:A6, XLOOKUP("Period 3", B1:G1, B1:G6)), 1, 0)  "Same period on the next day"

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Google Sheets: Highlight an Entire Column If Any Cell Has an Error

Google Sheets allows you to highlight an entire column if any cell has an...

Filter Top N per Category in Excel (Using FILTER & COUNTIFS)

You can use a combination of FILTER and COUNTIFS to filter the top N...

Rank per Group in Excel

You have two groups of 20 students each. How do you determine the rank...

Real-Time Excel Filtering Using Combo Box & FILTER Function

In this tutorial, you’ll learn how to set up real-time Excel filtering using a...

More like this

Google Sheets: Highlight an Entire Column If Any Cell Has an Error

Google Sheets allows you to highlight an entire column if any cell has an...

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

How to Extract Top N from Aggregated Query Results in Google Sheets

To summarize data in Google Sheets, you can use the QUERY function. However, if...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

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