Sub topic 6
Returning several columns at once
This chapter assumes you can already write a basic exact-match XLOOKUP and understand its six arguments. It also assumes you know absolute references such as $E$2. You need Excel for Microsoft 365, Excel 2021 or later, or Excel for the web, because multi-column results rely on dynamic arrays.
Why return more than one value
Suppose you have an employee table and want to pull the name, department and salary for one ID. With older lookup functions you would write three formulas, one per column. Each formula repeats the same search, and you have to keep the three in sync.
XLOOKUP can do the search once. If the return_array argument covers several columns, the function returns the whole matching row segment.
The basic pattern
Use this sample data. Row 1 holds headers, and the lookup ID goes in F2.
| Row | A | B | C | D |
|---|---|---|---|---|
| 1 | ID | Name | Department | Salary |
| 2 | 1001 | Amara | Sales | 52000 |
| 3 | 1002 | Ben | Finance | 61000 |
| 4 | 1003 | Chidi | Sales | 48000 |
| 5 | 1004 | Dana | Support | 45000 |
Enter this in G2:
=XLOOKUP(F2, A2:A10, B2:D10)With F2 set to 1003, the formula returns Chidi, Sales and 48000. You type it once, in G2. Excel spills the other two values into H2 and I2.
The key rule is that lookup_array and return_array must have the same number of rows. Here both span rows 2 to 10. The number of columns in return_array sets how wide the result is.
How spilling works
A spill is the way a dynamic array formula shows a multi-cell result. Only the first cell, G2, contains the formula. The cells it fills are the spill range, and Excel draws a thin blue border around them when you select any cell in it.
Three things follow from this:
- You cannot edit or delete a single cell in the spill range. Change the formula in
G2instead. - You can refer to the whole result with the spill operator
#. For example,=SUM(G2#)adds everything in the spill range, and the reference grows or shrinks with the result. - If you change
return_arrayto include a fourth column, the result grows by one cell automatically.
Adding matching headers
You can build the header row from the same columns. In G1 enter:
=B1:D1This spills the three header names. Keep the header range and the return range in step. If you change one to B:E, change the other too.
When the spill is blocked
If any cell in the target range already holds data, Excel shows #SPILL! in the formula cell. Selecting the cell shows a warning icon, and its menu offers "Select Obstructing Cells".
Common causes:
- Leftover values or notes in
H2orI2. - Cells that look empty but contain a space or a formula returning
"". - Merged cells inside the spill range.
- A formula placed inside an Excel Table. Tables do not allow spilled formulas, so move the formula outside the table or return one column per formula.
Clear the obstruction and the result appears without any further action.
Combining it with if_not_found
The fourth argument still works with a multi-column return. Add it as usual:
=XLOOKUP(F2, A2:A10, B2:D10, "ID not found")When the ID is missing, the formula returns the single text value. It appears only in G2, and H2 and I2 stay empty. If you want a placeholder in each column, supply an array constant of the same width:
=XLOOKUP(F2, A2:A10, B2:D10, {"-","-","-"})The braces create a one-row array with three items. Its width must equal the width of return_array, or the result will not line up with the columns. Here that width is three.
Returning only some of the columns
XLOOKUP returns the columns in the range as they are laid out. To return columns that are not next to each other, wrap the range in CHOOSECOLS. It is available in current Microsoft 365 builds and in Excel for the web.
=XLOOKUP(F2, A2:A10, CHOOSECOLS(A2:D10, 2, 4))CHOOSECOLS picks column 2 (Name) and column 4 (Salary) from A2:D10, in that order. The result is two cells wide. Because it takes column numbers relative to the range you give it, counting starts at column A here, not at column B.
If your Excel does not have CHOOSECOLS, HSTACK can do a similar job, as in HSTACK(B2:B10, D2:D10). Both functions are newer than XLOOKUP, so check them in your version first. The simplest fallback is two separate XLOOKUP formulas, which is slower but works anywhere XLOOKUP does.
Using the result inside another function
A multi-column result is an array, so other functions can consume it directly.
=SUM(XLOOKUP(F2, A2:A10, B2:D10))This formula adds all values in the matched row segment. It is useful when the return range holds only numbers, such as monthly sales columns. Be careful: if the range includes text columns, SUM skips the text, and you may add up fewer values than you intended.
To pick a single cell out of the result, use INDEX:
=INDEX(XLOOKUP(F2, A2:A10, B2:D10), 1, 2)This returns the second value of the first row, which is the Department. In practice you would normally return only that column instead, so this pattern matters mainly when one lookup feeds several different calculations.
To join the values into one text cell, use TEXTJOIN:
=TEXTJOIN(", ", TRUE, XLOOKUP(F2, A2:A10, B2:D10))For ID 1003 this gives Chidi, Sales, 48000.
Returning rows instead of columns
The same idea works sideways. If your lookup values sit in a header row, lookup_array is a single row and return_array has the same number of columns. The result then spills downward.
Suppose B1:E1 holds month names and B2:E10 holds nine rows of figures. With a month name in G1:
=XLOOKUP(G1, B1:E1, B2:E10)This returns the whole column for that month, as nine cells going down. The rule is the same as before, applied to the other axis: lookup_array and return_array must have the same number of columns when the lookup array is a row. This is also the building block for the two-way lookup, which a later chapter covers.
Errors specific to multi-value returns
| Symptom | Likely cause | Fix |
|---|---|---|
| `#VALUE!` | `lookup_array` and `return_array` differ in size, such as `A2:A10` with `B2:D9` | Make both span the same rows |
| `#SPILL!` | Cells in the spill range are not empty, or the formula is inside a Table | Clear the cells or move the formula |
| `#N/A` in every cell | No match, and no `if_not_found` supplied | Add the fourth argument |
| Only one value, with an `@` in the formula | The file opened in a version without dynamic arrays, or the formula was entered in a way that forces implicit intersection | Re-enter the formula in a dynamic-array version and remove the `@` |
| Wrong columns returned | Column numbers in `CHOOSECOLS` counted from the wrong starting column | Count from the first column of the range you passed |
A worked example
Goal: a lookup card that shows name, department and salary for any ID, with a clear message if the ID is wrong.
- Put the ID in
F2, with a label inF1. - In
G1, enter=B1:D1to spill the headers. - In
G2, enter the formula below.
=XLOOKUP(F2, A2:A10, B2:D10, "ID not found")- Type 1003 in
F2. The three values appear under the headers. - Type 9999.
G2shows "ID not found", andH2andI2stay blank. - In
K2, enter=SUM(G2#)and check what you get. The sum covers only the numbers in the spill. With a text name and department, it returns the salary alone. That shows why you should not sum ranges that mix types.
If step 4 returns #SPILL!, look for a stray value in H2 or I2.
Summary of the rules
- A
return_arraywith several columns returns several values from the matched row. - The result spills from the formula cell, so the cells to its right must be empty.
lookup_arrayandreturn_arraymust have the same number of rows (or columns, for a row lookup).if_not_foundgives one value unless you pass an array of matching width.- Use
CHOOSECOLSorHSTACKto select columns that are not adjacent.
Exercise
You enter =XLOOKUP(F2, A2:A10, B2:D9) and get #VALUE!. What is wrong, and how do you fix it?
Show answer
The lookuparray A2:A10 has nine rows, but the returnarray B2:D9 has eight. They must have the same number of rows. Change the return array to B2:D10.
Exercise
Your formula =XLOOKUP(F2, A2:A10, B2:D10) shows #SPILL! even though ID 1003 exists in the list. Give two possible causes.
Show answer
Any two of these: a value, space or empty-string formula in H2 or I2 blocks the spill; a merged cell lies in the spill range; the formula sits inside an Excel Table. The lookup itself succeeded. The result has nowhere to go.
Exercise
Write a formula that returns only Name (column B) and Salary (column D) for the ID in F2, with the text "Missing" when the ID is not found.
Show answer
=XLOOKUP(F2, A2:A10, CHOOSECOLS(A2:D10, 2, 4), "Missing")