LAMBDA · Lookup
Coalesce LAMBDA
xl.coalesce returns the first value that is not blank. Two empty cells and then Austin return Austin.
Syntax =xl.coalesce(values)
=LAMBDA(values,
LET(
filled, TOCOL(values, 1),
IFERROR(INDEX(filled, 1), "")
)
)Arguments
| Name | Required | What to pass |
|---|---|---|
| values | Required | A range, read in row order. The first non-blank wins. A formula that returns an empty string counts as blank. |
Examples
The first city that was actually typed
=xl.coalesce(A1:A3)Result Austin
| A | B | |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | Austin | |
| 4 | First | Austin |
xl.coalesce is the first filled cell. A shipping city that might be in any of three columns, two of them blank, comes back as the one someone typed. Austin under two blanks is Austin.
Zero is a value. An empty string from a formula is blank, because TOCOL’s ignore flag treats it that way.
Add it to the workbook
Copy the formula in the block above, including the line breaks. Choose Formulas, Name Manager, New. Set the name to xl.coalesce, the scope to Workbook, and paste into Refers to. Excel Labs can do the same step: open the Advanced Formula Environment, add that name, and save it back to the workbook. A cell then calls =xl.coalesce(...).
The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME? for LAMBDA even when it already has XLOOKUP, FILTER, or LET.
How it works
TOCOL with the ignore argument 1 drops blanks and empty strings and stacks what remains into a column. INDEX of position 1 is the first survivor. If every cell was blank, INDEX errors and IFERROR returns an empty string.
Limits
The scan is row by row, then across. A row of three cells is read left to right before the next row. Errors are not ignored. A #N/A stops the idea of “first good value” unless you remove it first.