DOUBLEXLOOKUP: Build the Excel Two-Way Lookup Function You’ve Been Waiting For

Dec 12, 2024 • 7 min read

A lookup formula that spills multiple results is useful. But what if you want to look up several items down the rows, several regions across the columns, and return every intersection from a single formula?

That is where DOUBLEXLOOKUP comes in.

This is a custom Excel function we can build with LAMBDA. It performs multiple two-way lookups and spills the results both vertically and horizontally. We will also give it familiar lookup options, including a missing-value fallback, wildcard matching, and separate search settings for each axis.

The name sounds ambitious. The calculation underneath is simply INDEX with two XMATCH functions. Once that works, we can package it into something much easier to reuse.

What You'll Learn

  • Combine INDEX with two XMATCH functions to spill multiple two-way lookup results.
  • Package the calculation in LAMBDA and save it as a reusable DOUBLEXLOOKUP function.
  • Control result shape, missing-value fallbacks, wildcard matching, and search direction through the function’s arguments.
  • Transfer DOUBLEXLOOKUP between workbooks by copying and pasting a cell containing the function.

Step 1: Build the Two-Way Lookup Formula

Our example has items down the left and regions across the top. Each number in the body belongs to one item and one region.

  • B4:B11: source item names.
  • C3:F3: region headings, ordered North, South, East, and West.
  • C4:F11: the values to return.
  • H4:H7: the items we want to find: Charlie, Echo, Golf, and Alpha.
  • I3:J3: the regions we want to return: North and East.

We want one formula in I4 to fill the result area. First, though, we need to find the correct rows.

Find the row positions with XMATCH

Enter this formula in I4:

=XMATCH(H4:H7,B4:B11,0,1)

Rather than supplying a single lookup value, we supply the entire range H4:H7. XMATCH returns a position for each item and spills those positions down the worksheet:

  • Charlie is in position 3.
  • Echo is in position 5.
  • Golf is in position 7.
  • Alpha is in position 1.

The final two arguments are 0 for an exact match and 1 for a first-to-last search. These are the normal defaults, but including them now makes it easier to see where our custom function’s settings will fit later.

Use INDEX to return values

Positions are useful to Excel, but we want the values at those positions. Wrap XMATCH in INDEX:

=INDEX(C4:C11,XMATCH(H4:H7,B4:B11,0,1))

INDEX now returns the North value for each requested item. We have multiple results from one formula, but we are still only returning one region.

Add a second XMATCH for the columns

INDEX also has a column-number argument. That is where the second XMATCH belongs:

=INDEX(
    C4:F11,
    XMATCH(H4:H7,B4:B11,0,1),
    XMATCH(I3:J3,C3:F3,0,1)
)

Notice that the INDEX array has expanded from C4:C11 to C4:F11. Finding the East column will not help if our return array only includes North.

The first XMATCH produces a vertical list of row positions. The second produces a horizontal list of column positions. INDEX uses both to return the intersections, creating a result that is four rows tall and two columns wide.

Excel worksheet with highlighted source values and a four-row, two-column lookup result
One INDEX formula returns the selected items and regions together.

That is the essential calculation complete: multiple two-way lookups, with results spilling in both directions.

Step 2: Turn the Formula into DOUBLEXLOOKUP

The formula works, but rebuilding it every time would get old fairly quickly. LAMBDA lets us turn the calculation into a named function with its own arguments.

Choose the function’s arguments

Our function needs five required inputs:

  1. v_lookup_value: the item or items to find on the vertical axis.
  2. v_lookup_array: the source list containing those items.
  3. h_lookup_value: the heading or headings to find on the horizontal axis.
  4. h_lookup_array: the source headings.
  5. return_array: the body of values containing the intersections.

We will also allow five optional inputs:

  • if_not_found: the value to return when the calculation encounters an error.
  • v_match_mode: the matching setting for the vertical lookup.
  • v_search_mode: the search direction for the vertical lookup.
  • h_match_mode: the matching setting for the horizontal lookup.
  • h_search_mode: the search direction for the horizontal lookup.

Written as a function signature, with square brackets indicating optional arguments, it looks like this:

=DOUBLEXLOOKUP(
    v_lookup_value,
    v_lookup_array,
    h_lookup_value,
    h_lookup_array,
    return_array,
    [if_not_found],
    [v_match_mode],
    [v_search_mode],
    [h_match_mode],
    [h_search_mode]
)

Separate settings for each axis are important. We might want an exact item match down the rows but a wildcard match across the headings. There is no reason to force both lookups to behave the same way.

Replace the worksheet references with parameters

Inside LAMBDA, the original cell references become parameter names. The return range becomes return_array, and each XMATCH receives the corresponding vertical or horizontal inputs.

We also wrap the calculation in IFERROR. For its fallback, ISOMITTED checks whether the user supplied if_not_found:

  • If the argument was omitted, return NA(), which produces #N/A.
  • If the argument was supplied, return that value instead.

Here is a complete definition to use. The ISOMITTED checks on the mode arguments explicitly preserve exact matching and first-to-last searching when those settings are left out.

=LAMBDA(
    v_lookup_value,
    v_lookup_array,
    h_lookup_value,
    h_lookup_array,
    return_array,
    if_not_found,
    v_match_mode,
    v_search_mode,
    h_match_mode,
    h_search_mode,
    IFERROR(
        INDEX(
            return_array,
            XMATCH(
                v_lookup_value,
                v_lookup_array,
                IF(ISOMITTED(v_match_mode),0,v_match_mode),
                IF(ISOMITTED(v_search_mode),1,v_search_mode)
            ),
            XMATCH(
                h_lookup_value,
                h_lookup_array,
                IF(ISOMITTED(h_match_mode),0,h_match_mode),
                IF(ISOMITTED(h_search_mode),1,h_search_mode)
            )
        ),
        IF(ISOMITTED(if_not_found),NA(),if_not_found)
    )
)

One detail worth noting: the fallback uses IFERROR, so it handles calculation errors generally, not only missing matches. The argument is called if_not_found for familiarity, but its behavior is broader than XLOOKUP’s missing-match argument.

Test the LAMBDA before naming it

Before saving the function, test it directly in the worksheet. Append the following argument list immediately after the final closing parenthesis of the LAMBDA definition:

(H4:H7,B4:B11,I3:J3,C3:F3,C4:F11)

This calls the LAMBDA using the same five ranges as our original formula. The optional arguments are left out, so the function uses its defaults.

Calculate the formula. It should return the same four-row, two-column result as the INDEX and XMATCH combination. Now we know the calculation still works after replacing the references with parameters.

Save DOUBLEXLOOKUP as a workbook name

  1. Copy the LAMBDA definition, including its leading equals sign, but exclude the appended test arguments.
  2. Go to Formulas > Define Name.
  3. Enter DOUBLEXLOOKUP as the name.
  4. Leave the scope set to Workbook.
  5. Paste the LAMBDA definition into Refers to.
  6. Click OK.
Excel New Name dialog showing DOUBLEXLOOKUP with workbook scope and a formula in the Refers to field

DOUBLEXLOOKUP is now available as a custom function in that workbook. No need to keep the long calculation in every result cell.

Step 3: Use DOUBLEXLOOKUP in Your Worksheet

Delete the test formula from I4 and start typing =DOUBLE. DOUBLEXLOOKUP should appear in Excel’s autocomplete list. Press Tab to accept it, then supply the five required arguments:

=DOUBLEXLOOKUP(H4:H7,B4:B11,I3:J3,C3:F3,C4:F11)

That is rather more practical. We still get all the requested item-and-region intersections, but the worksheet formula now describes the task much more clearly.

Return zero for missing values

Suppose we replace Echo in the lookup list with Indigo, which does not exist in the source items. With no fallback supplied, the corresponding results return #N/A.

To return zero instead, add a sixth argument:

=DOUBLEXLOOKUP(H4:H7,B4:B11,I3:J3,C3:F3,C4:F11,0)

The missing item now produces zeros, while the valid items continue returning their values.

Return paired results in a single column

A two-way lookup does not have to produce a two-dimensional result.

In the first example, the item requests run vertically and the region requests run horizontally. That arrangement asks Excel for every combination of the requested items and regions.

But suppose each row contains an item and its own region:

  • H14:H17: the requested items.
  • I14:I17: the corresponding regions.

Enter this formula in J14:

=DOUBLEXLOOKUP(H14:H17,B4:B11,I14:I17,C3:F3,C4:F11)

Because both sets of lookup values are vertical and aligned, the function returns one result per pair. The output spills down a single column, even though each result comes from a two-dimensional source range.

Excel worksheet with a vertical result column beside item and region pairs and highlighted source cells
Aligned item and region lists return one intersection per row.

The orientation of the lookup inputs controls the result’s shape. A vertical list combined with horizontal headings creates a grid. Two aligned vertical lists create paired results.

Use wildcard matching on the horizontal axis

Now change the North heading in I3 to *st*. This pattern asks for a heading containing the letters st anywhere in the text.

It will not work with the default exact-match setting. We need to set h_match_mode to 2, which enables wildcard matching:

=DOUBLEXLOOKUP(
    H4:H7,
    B4:B11,
    I3:J3,
    C3:F3,
    C4:F11,
    0,
    ,
    ,
    2
)

The empty argument positions skip v_match_mode and v_search_mode. The 2 therefore lands in the horizontal match-mode position.

Both East and West contain st. With a first-to-last search through North, South, East, and West, East is the first match, so the function returns East’s values.

We can also control the search direction separately for each axis. A search-mode value of -1 searches last to first, while 1 searches first to last. The same underlying calculation can therefore support exact item lookups, wildcard headings, and reverse searches without rebuilding the formula.

Step 4: Move DOUBLEXLOOKUP to Another Workbook

We have done the work of creating the function. Surely we do not have to build it again for every workbook?

Good news: we do not.

  1. Select a cell containing a DOUBLEXLOOKUP formula.
  2. Copy the cell.
  3. Paste it normally into another workbook.
  4. Clear the pasted cell’s contents if you no longer need that formula.

The DOUBLEXLOOKUP name transfers with the formula and remains available in the destination workbook, even after the pasted cell’s contents are cleared. Start typing =DOUBLE there to confirm that the function appears.

Use a normal paste for this, not a values-only paste. The formula is what carries the custom function across.

One Formula, Two Lookup Directions

DOUBLEXLOOKUP takes a useful INDEX and XMATCH combination and turns it into a reusable worksheet function. It can return a grid of item-and-region intersections or a single column of paired results, with optional error handling and independent matching and search settings.

The underlying idea is straightforward: find the rows, find the columns, and return their intersections. LAMBDA means we only need to build that logic once. That is the practical part.

Share

Excel Off The Grid

I help you reduce repetitive Excel work with practical guides to formulas, Power Query, reporting, and automation.

© 2026 Excel Off The Grid
Powered by Convella