Better Than XLOOKUP? Build Your Own SUPERXLOOKUP

Nov 21, 2024 • 7 min read

XLOOKUP is fantastic, but try looking up several items and returning several columns at the same time. In the example we will build, it returns only a single column rather than the complete block of results we want.

CHOOSEROWS combined with XMATCH gets us closer. However, introduce a lookup value that does not exist, and the entire result becomes a single #N/A error. That's definitely not what we want.

The solution? SUPERXLOOKUP: a custom Excel function that looks up multiple values, returns multiple rows and columns, and handles missing items without losing the valid results. We can build it ourselves using standard worksheet functions and LAMBDA.

What You'll Learn

  • Combine INDEX, XMATCH, and SEQUENCE to return multiple lookup results across rows and columns.
  • Handle missing matches without losing the valid results in the spilled array.
  • Create a reusable LAMBDA function with optional replacement, match-mode, and search-mode arguments.
  • Transfer SUPERXLOOKUP to another workbook by copying a cell containing the function.

Table of Contents

What does SUPERXLOOKUP do?

SUPERXLOOKUP uses the familiar XLOOKUP argument structure:

=SUPERXLOOKUP(lookup_value,lookup_array,return_array,[if_not_found],[match_mode],[search_mode])

The important difference is that our custom function can return a two-dimensional result for multiple lookup values.

  • Vertical lookup values: Find several items and return all four quarterly columns for each item.
  • Horizontal lookup values: Find several quarter headings and return all the item rows for those quarters.
  • Missing values: Return a replacement such as zero, or retain #N/A when no replacement is supplied.
Excel worksheet with an item and quarterly data table, a spilled result block, and a SUPERXLOOKUP annotation
One formula returns a complete block of results, spilling vertically and horizontally.

You won't find SUPERXLOOKUP built into Excel. We will create it as a workbook-level named function. You need a modern version of Excel that supports the functions used here, including LAMBDA and dynamic arrays.

1. Understand the XLOOKUP and CHOOSEROWS problem

Our source data has an Item column and four quarterly columns named Q1 through Q4. For the formulas below, we'll call the Excel table Data. Use your own table name if it is different.

The vertical lookup values are in H6:H9. A normal XLOOKUP would be:

=XLOOKUP(H6:H9,Data[Item],Data[[Q1]:[Q4]])

Here, we want four lookup values to return four columns each. However, this formula returns only a single column. It does not produce the complete rectangular result.

We can get that rectangle by asking XMATCH to find the row positions and passing those positions to CHOOSEROWS:

=CHOOSEROWS(Data[[Q1]:[Q4]],XMATCH(H6:H9,Data[Item]))

This works beautifully while every lookup value exists. XMATCH supplies the matching row numbers, and CHOOSEROWS returns those rows from the quarterly data.

But change one lookup value to an item that is not in the source data, and the whole formula fails with a single #N/A. We need a calculation that keeps the valid results and isolates the missing items.

2. Replace CHOOSEROWS with INDEX

INDEX gives us more control because we can supply arrays for both its row and column arguments.

=INDEX(
    Data[[Q1]:[Q4]],
    XMATCH(H6:H9,Data[Item]),
    SEQUENCE(1,COLUMNS(Data[[Q1]:[Q4]]))
)

There are three parts to this calculation:

  1. The return array: Data[[Q1]:[Q4]] contains the values we want back.
  2. The row numbers: XMATCH returns a vertical array of positions for the items in H6:H9.
  3. The column numbers: SEQUENCE generates a horizontal array containing 1, 2, 3, and 4.

The COLUMNS function tells SEQUENCE how many column numbers to generate. Rather than hard-coding four columns, the formula uses the width of the return array.

Now INDEX combines the vertical row positions with the horizontal column positions. The result spills in both directions, and a missing lookup value produces errors only in its corresponding result row. The rest of the results remain intact. That's much better.

Excel worksheet showing a spilled result block with an annotation pointing to errors only on missing values
INDEX preserves the valid results instead of collapsing the entire calculation into one error.

Add a replacement for missing values

XLOOKUP has an if_not_found argument, so let's give our calculation similar behavior. Wrap it in IFERROR and use zero as the replacement:

=IFERROR(
    INDEX(
        Data[[Q1]:[Q4]],
        XMATCH(H6:H9,Data[Item]),
        SEQUENCE(1,COLUMNS(Data[[Q1]:[Q4]]))
    ),
    0
)

The valid results remain unchanged, while the errors become zeros.

One important distinction: IFERROR catches all errors in the wrapped calculation, not just missing matches. That is worth remembering if you need to investigate an unexpected replacement value later.

3. Make the formula easier to work with using LET

Our solution is coming together, but it currently works only with the vertical lookup arrangement. If we simply change the lookup values to the horizontal range I12:K12 and search the quarterly headers, the calculation does not return the correct result.

Before adding another calculation branch, let's make the formula easier to read. LET allows us to assign names to the inputs and use those names throughout the calculation.

=LET(
    lookup_value,H6:H9,
    lookup_array,Data[Item],
    return_array,Data[[Q1]:[Q4]],
    if_not_found,0,
    match_mode,0,
    search_mode,1,
    IFERROR(
        INDEX(
            return_array,
            XMATCH(lookup_value,lookup_array,match_mode,search_mode),
            SEQUENCE(1,COLUMNS(return_array))
        ),
        if_not_found
    )
)

Here, match_mode is set to 0 for an exact match, and search_mode is set to 1 to search from first to last.

We now have names corresponding to the six familiar XLOOKUP arguments:

  • lookup_value: The values to find.
  • lookup_array: The column or row to search.
  • return_array: The data to return results from.
  • if_not_found: The replacement value used by our error handling.
  • match_mode: The matching behavior passed to XMATCH.
  • search_mode: The search behavior passed to XMATCH.

XMATCH accepts match-mode and search-mode arguments too, so we can pass them straight through rather than building separate matching logic.

4. Support horizontal lookups as well

For a vertical lookup, XMATCH supplies the row numbers and SEQUENCE supplies every column number. For a horizontal lookup, we need to reverse those roles:

  • Row numbers: Generate every row number with SEQUENCE(ROWS(return_array)).
  • Column numbers: Use XMATCH to locate the requested headings.

The horizontal INDEX calculation is therefore:

INDEX(
    return_array,
    SEQUENCE(ROWS(return_array)),
    XMATCH(lookup_value,lookup_array,match_mode,search_mode)
)

We can choose between the two calculations with this test:

COLUMNS(lookup_value)=1

If the lookup values occupy one column, use the vertical calculation. Otherwise, use the horizontal calculation.

That gives us the following structure inside LET:

IF(
    COLUMNS(lookup_value)=1,
    IFERROR(
        INDEX(
            return_array,
            XMATCH(lookup_value,lookup_array,match_mode,search_mode),
            SEQUENCE(1,COLUMNS(return_array))
        ),
        if_not_found
    ),
    IFERROR(
        INDEX(
            return_array,
            SEQUENCE(ROWS(return_array)),
            XMATCH(lookup_value,lookup_array,match_mode,search_mode)
        ),
        if_not_found
    )
)

To test the horizontal branch, change lookup_value to I12:K12 and lookup_array to Data[[#Headers],[Q1]:[Q4]]. Keep the return array as the quarterly data.

Now we can request several quarter headings across a row and return the corresponding data columns for every item. Fantastic. We have a calculation that works with both lookup arrangements.

5. Turn the calculation into SUPERXLOOKUP

The formula works, but we don't want to rebuild it every time. This is where LAMBDA comes in.

LAMBDA turns the calculation into a reusable custom function. The input names currently defined by LET become the function's parameters, so we can remove the LET wrapper and its fixed input values.

The first three parameters are required. The final three are optional, shown in square brackets:

  • [if_not_found]
  • [match_mode]
  • [search_mode]

Handle an omitted if_not_found argument

There is one more detail to resolve. If the user does not supply an if_not_found value, we want missing matches to return #N/A, rather than automatically substituting zero.

ISOMITTED checks whether a LAMBDA argument was supplied. We can use it like this:

IF(ISOMITTED(if_not_found),NA(),if_not_found)

If the argument is omitted, NA() supplies the #N/A error. Otherwise, the formula uses the supplied replacement. We need this logic in both calculation branches.

The complete SUPERXLOOKUP formula

Copy the following definition when you are ready to create the named function:

=LAMBDA(
    lookup_value,
    lookup_array,
    return_array,
    [if_not_found],
    [match_mode],
    [search_mode],
    IF(
        COLUMNS(lookup_value)=1,
        IFERROR(
            INDEX(
                return_array,
                XMATCH(lookup_value,lookup_array,match_mode,search_mode),
                SEQUENCE(1,COLUMNS(return_array))
            ),
            IF(ISOMITTED(if_not_found),NA(),if_not_found)
        ),
        IFERROR(
            INDEX(
                return_array,
                SEQUENCE(ROWS(return_array)),
                XMATCH(lookup_value,lookup_array,match_mode,search_mode)
            ),
            IF(ISOMITTED(if_not_found),NA(),if_not_found)
        )
    )
)

For more background on creating reusable worksheet functions, Microsoft's LAMBDA documentation explains how named functions work.

Save the function with workbook scope

  1. Copy the complete LAMBDA formula, including the opening equals sign.
  2. Go to the Formulas ribbon and select Define Name.
  3. Enter SUPERXLOOKUP in the Name box.
  4. Set Scope to Workbook.
  5. Paste the LAMBDA formula into the Refers to box.
  6. Click OK.

SUPERXLOOKUP has been born. We can now use it in worksheet cells just like a regular function.

6. Test vertical and horizontal results

Look up several items and return all four quarters

In cell I6, enter:

=SUPERXLOOKUP(H6:H9,Data[Item],Data[[Q1]:[Q4]],0)

The formula finds the items in H6:H9 and returns their Q1 through Q4 values. It spills down for the requested items and across for the four quarterly columns.

Because the fourth argument is zero, a missing item returns zeros in its result row.

Look up several quarter headings and return every item row

In cell I13, enter:

=SUPERXLOOKUP(
    I12:K12,
    Data[[#Headers],[Q1]:[Q4]],
    Data[[Q1]:[Q4]]
)

This time, the lookup values run horizontally. SUPERXLOOKUP finds the requested quarterly headers and returns their corresponding data columns.

We have omitted if_not_found, so any heading that cannot be found returns #N/A in its result column. The valid columns still return their values.

Excel worksheet with vertical and horizontal result blocks and a column of N/A errors in the lower result
The horizontal test returns the requested columns while retaining errors for a missing heading.

That's exactly the behavior we wanted: multiple lookup values, multiple return rows and columns, and control over missing results.

7. Use SUPERXLOOKUP in other workbooks

Because SUPERXLOOKUP is saved as a workbook-level name, the function travels with the workbook. If you send the file to somebody with a compatible modern version of Excel, they can use the function within that workbook too.

You can also transfer it to another workbook without defining the name again:

  1. Copy a cell containing a SUPERXLOOKUP formula.
  2. Paste it into a cell in the destination workbook.
  3. Use SUPERXLOOKUP in the destination workbook with the appropriate data references.

The named function is copied into the destination workbook. Even if you delete the pasted formula afterward, SUPERXLOOKUP remains available there. Start typing =SUPER in another cell, and it appears in the formula autocomplete list.

A reusable solution to the two-direction spill problem

The real improvement is not just a shorter formula. We have taken a useful calculation, added error handling, made it work vertically and horizontally, and packaged it into a function we can reuse.

INDEX, XMATCH, and SEQUENCE do the calculation. LAMBDA gives us the familiar interface. Once SUPERXLOOKUP is saved, getting a complete block of lookup results becomes a single function call.

If you want to build more time-saving Excel workflows, my Excel Academy brings together courses, tools, community, and support to help make working late a thing of the past.

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