Skip to main content
ExcelXLOOKUP + XLOOKUPCombo RecipeTwo-Way LookupAdvanced Lookup

The Problem

Have you ever found yourself staring at a sprawling spreadsheet, needing to pull a specific piece of data that sits at the intersection of a particular row and column? Perhaps you need the sales figure for "Product X" in "Q3," or the inventory level for "Warehouse B" of "Item Z." A simple XLOOKUP function, while incredibly powerful for one-dimensional searches, falls short when you have two distinct criteria. You're left manually scanning, scrolling, and risking critical errors.

This common scenario leads many Excel users down a frustrating path. You might have tried various combinations of VLOOKUP with MATCH, or even the more robust INDEX with MATCH and MATCH. While these methods work, they can often be complex to construct and even harder for others to decipher. You're searching for a clearer, more intuitive way to perform these crucial two-way lookups.

What is XLOOKUP + XLOOKUP? The XLOOKUP + XLOOKUP combination is an advanced Excel technique that enables powerful two-way data lookups, allowing you to retrieve specific values from a table based on criteria from both rows and columns. It's commonly used to pinpoint data where two distinct identifiers intersect, offering a modern and often more readable alternative to older lookup methods.

Business Context & Real-World Use Case

Consider a sales operations manager tasked with analyzing performance across various product lines and quarterly periods. Their core challenge is to quickly retrieve the exact sales revenue for a specific product during a particular quarter from a large, evolving sales database. This isn't a one-off task; it's a daily requirement for reporting, forecasting, and strategic decision-making.

Doing this manually is a recipe for disaster. Imagine sifting through thousands of rows and dozens of columns to find "Laptop Pro" sales for "Q2." Not only is it excruciatingly time-consuming, but the risk of human error—selecting the wrong cell, misreading a row, or misaligning a column—is incredibly high. One mistake can ripple through a financial report, leading to incorrect projections or misallocated resources. The business value of automating this process cannot be overstated.

In my years as a data analyst, I've seen teams waste countless hours manually updating reports or making critical decisions based on outdated information, simply because retrieving combined data was too cumbersome. Implementing a robust XLOOKUP + XLOOKUP solution transforms this pain point into an efficiency gain. It ensures data accuracy, frees up valuable employee time for higher-level analysis, and empowers managers to access vital information instantly, fostering quicker and more informed business strategies. This combo is a true game-changer for dynamic reporting.

The Ingredients: Understanding XLOOKUP + XLOOKUP's Setup

The XLOOKUP + XLOOKUP combination leverages the power of Excel's XLOOKUP function by nesting one inside the other. The inner XLOOKUP dynamically determines the correct row or column range for the outer XLOOKUP to perform its final lookup. This creates a flexible and intuitive way to search across both rows and columns simultaneously.

Here's the essential syntax for this powerful combo:

=XLOOKUP(val1, range1, XLOOKUP(val2, range2, return_matrix))

Let's break down each parameter to understand its role in this lookup masterpiece:

Parameter Description
val1 The first lookup value you want to find. This typically corresponds to a row header or a unique identifier in your data set.
range1 The array or range where val1 will be searched. This usually represents your row headers or the column containing your unique row identifiers.
val2 The second lookup value you want to find. This typically corresponds to a column header or a second criterion in your data set.
range2 The array or range where val2 will be searched. This usually represents your column headers or the row containing your unique column identifiers.
return_matrix The full data table or matrix from which the final result will be retrieved. This must encompass all potential values that could be returned based on val1 and val2.

The magic happens when the inner XLOOKUP (which looks for val2 within range2 and specifies the return_matrix) effectively narrows down the search area for the outer XLOOKUP. The inner XLOOKUP doesn't return a single value, but rather an entire array (a row or column slice) from the return_matrix. This array then becomes the return_array argument for the outer XLOOKUP, which uses val1 and range1 to pinpoint the final desired value within that dynamic array. Understanding which XLOOKUP returns the array is crucial for successful implementation.

The Recipe: Step-by-Step Instructions

Let's prepare a realistic example to illustrate how to wield the XLOOKUP + XLOOKUP combo. Imagine you're a product manager needing to quickly pull the revenue for specific products in particular quarters.

Here's our sample sales data in cells A1:E4:

Cell A B C D E
1 Product Q1 Sales Q2 Sales Q3 Sales Q4 Sales
2 Laptop Pro $120,000 $150,000 $130,000 $180,000
3 Ultrabook X $90,000 $110,000 $95,000 $140,000
4 Gaming Rig $180,000 $200,000 $175,000 $230,000

And here are our lookup criteria:

Cell G H
1 Lookup Product: Lookup Quarter:
2 Ultrabook X Q3 Sales
3 Result:

We want to find the sales figure for "Ultrabook X" in "Q3 Sales" and display it in cell H3.

Follow these steps to construct your XLOOKUP + XLOOKUP formula:

  1. Prepare Your Data: First, ensure your sales data table is well-structured as shown above, with clear row and column headers. Your lookup criteria (Product and Quarter) should be in separate cells, in our example G2 and H2.

  2. Select Your Result Cell: Click on cell H3, where you want the final sales figure to appear.

  3. Begin the Outer XLOOKUP: Start by typing the outer XLOOKUP formula: =XLOOKUP(. This XLOOKUP will handle finding the correct row based on your product.

  4. Define val1 and range1:

    • For val1, select cell G2 (which contains "Ultrabook X").
    • For range1, select the range of your product names, A2:A4.
    • At this point, your formula looks like: =XLOOKUP(G2, A2:A4,
  5. Introduce the Inner XLOOKUP: Now, for the return_array argument of the outer XLOOKUP, we'll nest another XLOOKUP. This inner XLOOKUP will dynamically identify the correct column (Q1, Q2, etc.) based on your quarter lookup value. Type XLOOKUP(.

  6. Define Inner val2 and range2:

    • For the inner val2, select cell H2 (which contains "Q3 Sales").
    • For the inner range2, select the range of your quarter headers, B1:E1.
    • Your formula now progresses to: =XLOOKUP(G2, A2:A4, XLOOKUP(H2, B1:E1,
  7. Define the Final return_matrix: The return_matrix for the inner XLOOKUP is the entire data body of your sales figures, excluding the product and quarter headers. Select B2:E4. This is critical, as the inner XLOOKUP will find "Q3 Sales" in B1:E1 and then return the entire Q3 column ($130,000, $95,000, $175,000) as an array to the outer XLOOKUP.

  8. Complete the Formula: Close the parentheses for both XLOOKUP functions.
    The final working formula in cell H3 should be:
    =XLOOKUP(G2, A2:A4, XLOOKUP(H2, B1:E1, B2:E4))

  9. Observe the Result: Press Enter. Excel will instantly return $95,000 in cell H3. This is the exact sales figure for "Ultrabook X" in "Q3 Sales," successfully retrieved using a single, elegant XLOOKUP + XLOOKUP formula. This demonstrates the seamless capability of nested XLOOKUP to handle complex two-dimensional lookups with clarity.

Pro Tips: Level Up Your Skills

Mastering XLOOKUP + XLOOKUP goes beyond basic syntax. Here are some expert tips to enhance your formulas and reporting:

  • Understand the Array Return: This is often easier to read than INDEX/MATCH/MATCH, but ensure you understand which XLOOKUP returns the array. The inner XLOOKUP is responsible for returning an array (a dynamic row or column) that the outer XLOOKUP then searches within. Visualizing this dynamic array is key to debugging and understanding the formula's flow.

  • Leverage if_not_found for Robust Error Handling: Don't let your users see unsightly #N/A errors. Both XLOOKUP functions include an optional if_not_found argument. For example, =XLOOKUP(val1, range1, XLOOKUP(val2, range2, return_matrix, "Column Not Found"), "Row Not Found"). This allows you to return custom, user-friendly messages if either the row or column lookup value isn't found, making your spreadsheets more professional.

  • Utilize Match Modes Beyond Exact: While XLOOKUP defaults to an exact match (match_mode = 0), don't forget the power of its other match_mode arguments. You can specify 1 for an exact match or the next larger item, -1 for an exact match or the next smaller item, or 2 for a wildcard character match. This flexibility is incredibly valuable for approximating data or handling partial matches in various business scenarios.

  • Combine with Excel Tables for Dynamic Ranges: Instead of fixed cell references like A2:A4, convert your data into an Excel Table (Insert > Table). Then, refer to table columns by their structured reference names, e.g., Table1[Product]. This makes your XLOOKUP + XLOOKUP formula automatically adjust as you add or remove rows and columns from your table, eliminating the need to manually update range references. This dynamic capability is invaluable for growing datasets.

Troubleshooting: Common Errors & Fixes

Even experienced Excel users can encounter hiccups with nested functions like XLOOKUP + XLOOKUP. Here are the most common issues and how to gracefully resolve them:

1. #N/A Error: Value Not Found

  • What it looks like: Your cell displays #N/A.
  • Why it happens: This error indicates that XLOOKUP couldn't find one or both of your lookup values (val1 or val2) in their specified lookup ranges (range1 or range2). Common culprits include typos, extra spaces, or case sensitivity issues (though XLOOKUP is generally case-insensitive for text by default).
  • How to fix it:
    1. Verify Lookup Values: Double-check that val1 (e.g., "Ultrabook X") and val2 (e.g., "Q3 Sales") exactly match the corresponding entries in your range1 and range2. Even a slight spelling difference will cause a #N/A.
    2. Trim Accidental Spaces: Use the TRIM() function around your lookup values, especially if they are user-entered. For example, change G2 to TRIM(G2) within your XLOOKUP to remove any accidental leading or trailing spaces that could prevent a match.
    3. Check Data Types: Ensure your lookup values have the same data type as the values in your lookup arrays. If one is text and the other is a number (even if they look the same), XLOOKUP may fail to find a match.
    4. Use if_not_found Argument: Proactively handle #N/A errors by adding the if_not_found argument to both XLOOKUP functions. This replaces #N/A with a custom message, making your output much clearer.

2. #VALUE! Error: Mismatched Data Types or Inconsistent Ranges

  • What it looks like: You see #VALUE! in your formula cell.
  • Why it happens: This error often points to an issue with data types or range inconsistencies. While less common than #N/A for XLOOKUP, it can occur if a lookup range is expecting a numerical value but gets text, or if a lookup array is not correctly formed. With nested XLOOKUP, it can also signal that the inner XLOOKUP is not returning a valid array for the outer XLOOKUP to process.
  • How to fix it:
    1. Inspect Data Types: Ensure that if val1 or val2 are numbers (like employee IDs), their respective range1 or range2 also contain numbers, not numbers stored as text.
    2. Verify return_matrix Integrity: Double-check that your return_matrix (e.g., B2:E4 in our example) is a contiguous range of cells. Any broken ranges or non-rectangular selections could cause this error.
    3. Test Inner XLOOKUP Separately: A powerful debugging technique is to isolate and evaluate the inner XLOOKUP portion of your formula. Select XLOOKUP(H2, B1:E1, B2:E4) in the formula bar and press F9. This will show you the array it returns. If this array is not a coherent single row or column of values, it can cause the outer XLOOKUP to throw a #VALUE! error.

3. Incorrect Result or #REF! Error: Misaligned Return Matrices

  • What it looks like: The formula returns a value, but it's clearly the wrong one, or you get a #REF! error.
  • Why it happens: This is the critical error often encountered when selecting misaligned return matrices compared to the lookup arrays. For a nested XLOOKUP, this means the range1 (for val1) doesn't correctly align with the rows of the array returned by the inner XLOOKUP. Similarly, range2 (for val2) must correctly align with the columns of the return_matrix provided to the inner XLOOKUP. If the row headers in range1 don't perfectly correspond to the rows in the data body (return_matrix), or if column headers in range2 don't align with the columns in the data body, XLOOKUP will point to the wrong cell or fail entirely.
  • How to fix it:
    1. Visual Alignment Check: Carefully examine your formula's ranges. range1 (e.g., A2:A4 for product names) must directly correspond to the rows within your return_matrix (e.g., B2:E4). Likewise, range2 (e.g., B1:E1 for quarter headers) must align precisely with the columns within your return_matrix. The number of rows in range1 should match the number of data rows in return_matrix, and the number of columns in range2 should match the number of data columns.
    2. Consistent Starting Rows/Columns: If your data starts at row 2, all ranges referring to that data (e.g., range1 and the return_matrix) must also start at row 2. Avoid using A1:A4 for range1 if your data actually begins in A2. This ensures consistent indexing.
    3. Step-by-Step Evaluation (F9): Select the entire inner XLOOKUP portion of your formula (XLOOKUP(val2, range2, return_matrix)) in the formula bar and press F9. This will evaluate that part of the formula and show you the array it's returning. Check if this array contains the correct slice of data you expect. If it looks correct, the problem is likely with the outer XLOOKUP's range1 not aligning with this returned array's rows.

Quick Reference

Feature Description
Purpose Perform a two-way lookup (based on both row and column criteria) in a table.
Syntax =XLOOKUP(val1, range1, XLOOKUP(val2, range2, return_matrix))
Key Idea The inner XLOOKUP dynamically identifies and returns a specific row or column array, which the outer XLOOKUP then searches to find the exact intersection.
Common Use Case Retrieving data like sales figures, inventory levels, or employee details based on two identifiers (e.g., Product and Quarter).
Best Practice Understand that the inner XLOOKUP is responsible for generating the dynamic array that the outer XLOOKUP then interrogates. This mental model is vital.

Related Functions

👨‍💻

Written by The Head Chef

Former 10-year Financial Analyst who survived countless month-end closes. I build these recipes to save you from weekend-ruining spreadsheet errors.

Read the full story →

You might also find these useful 💡