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 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.

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

More like this

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

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.