Sub topic 10
Handling empty results and #CALC!
What this chapter assumes
You should already be comfortable with these ideas from earlier chapters:
- A formula can return an array that spills into neighboring cells.
- FILTER, SORT, SORTBY, UNIQUE and SEQUENCE return arrays.
- The anchor cell holds the formula, and the spill range is the block of cells it fills.
- The
#operator refers to a whole spill range.
This chapter covers what happens when an array formula has nothing to return, why Excel shows #CALC!, and how to build formulas that handle that case on purpose.
Why an empty array is a problem
A normal formula always returns at least one value. An array formula is different. A filter that matches no rows has a result with zero rows and zero columns. Excel has no way to draw a block with no cells, so it can't spill anything.
In that situation the anchor cell shows #CALC!. This error means the calculation engine hit a condition it can't complete. The most common cause is an empty array. Other causes exist, and the last section lists them.
The error does not mean your formula is wrong. It means the data, at this moment, produced no result. If the data changes and a row matches, the error goes away and the spill returns.
Seeing the error with FILTER
Suppose A2:C20 holds a product, a region and a sales amount, and no sales amount is above 100. This formula has nothing to return:
=FILTER(A2:C20,C2:C20>100)The anchor cell shows #CALC!. FILTER found zero matching rows, so the result is an empty array.
FILTER has a third argument, if_empty. It is the value to show instead of the error when no row matches:
=FILTER(A2:C20,C2:C20>100,"No matches")When no row matches, the cell shows the text No matches. When rows do match, the formula spills them as usual and the third argument is ignored.
Choosing what the fallback should be
The if_empty value can be any single value. The right choice depends on what reads the result.
| Fallback | Example | Use it when |
|---|---|---|
| Text message | `"No matches"` | A person reads the cell and needs to know the result is empty by design. |
| Empty text | `""` | You want a blank-looking cell. |
| Zero | `0` | Another formula does arithmetic on the result. |
| Empty row of values | `{"","",""}` | You want the shape to stay three columns wide. |
Each choice has a cost, so check the downstream use before you pick one.
- A text message in a numeric column breaks arithmetic.
=SUM(E2#)ignores text, but=E2#*2returns#VALUE!for it. - Empty text
""looks blank but is not empty.ISBLANKreturns FALSE for it, andCOUNTAcounts it. - A one-value fallback produces a one-column result, even if the normal result has three columns. Charts or formulas that expect three columns may behave differently when the fallback appears.
Other functions that can return an empty array
FILTER is the usual source, but it isn't the only one. Any function that can end up with zero rows or columns can return #CALC!.
- Functions built on FILTER, such as
=SORT(FILTER(A2:C20,C2:C20>100)), inherit the problem. The empty array passes through SORT and the error appears in the anchor cell. TAKEandDROPreturn an empty array when you ask for zero rows or columns, or drop everything. Excel returns#CALC!in these cases.SEQUENCEwith zero rows, such as=SEQUENCE(0), returns#CALC!. This matters when the row count comes from another cell.
The wrapped-function case needs the most care. Put the guard on the inner FILTER, where the empty array starts:
=SORT(FILTER(A2:C20,C2:C20>100,"No matches"))Now SORT receives the one-cell text No matches instead of an empty array. SORT sorts a single value without error, and the cell shows the message.
You can instead wrap the whole formula in IFERROR:
=IFERROR(SORT(FILTER(A2:C20,C2:C20>100)),"No matches")This works, but it catches every error, including real mistakes. Prefer the if_empty argument when the function has one. See the warning below.
Testing for an empty result directly
Sometimes you want a formula to branch on whether results exist. You can test for the empty case without trapping every error. ISERR is not suitable here, because it does not catch #N/A but it does catch #CALC!, which mixes cases. A more precise test counts the rows first:
=LET(
hits, FILTER(A2:C20, C2:C20>100, ""),
IF(COLUMNS(hits)=1, "No matches", hits)
)Here the fallback is empty text, so hits is a single cell when nothing matches. The formula checks the width of hits. Because the source data has three columns, a width of 1 can only mean the fallback was returned. Then the formula replaces it with a clearer message.
A simpler pattern counts matches before filtering:
=IF(COUNTIF(C2:C20,">100")=0, "No matches", FILTER(A2:C20,C2:C20>100))This reads clearly. The cost is that the condition appears twice, so the two copies can drift apart when someone edits one of them. LET removes that duplication:
=LET(
keep, C2:C20>100,
IF(SUM(--keep)=0, "No matches", FILTER(A2:C20, keep))
)keep is an array of TRUE and FALSE values. --keep turns them into 1 and 0, and SUM counts the matches. If the count is zero, the formula returns the message. Otherwise it returns the filtered rows.
Reading downstream formulas
An empty result affects every formula that points at it. Say E2 holds a FILTER formula and F1 holds:
=SUM(E2#)If E2 shows #CALC!, then E2# is also an error, and so is the sum. A single empty result can turn a whole column of dependent cells to errors.
Two habits prevent this:
- Give the fallback a type that the downstream formulas can use. For a numeric column, use
0as the third argument of FILTER, not text. - Guard the dependent formula as well when the upstream formula may return text. For example,
=IF(ISNUMBER(E2),SUM(E2#),0).
Other causes of #CALC!
An empty array is the most common cause, but not the only one. #CALC! also appears in these cases:
- A calculation returns an array of arrays. Excel can't spill a nested array, for example when a function returns an array in each cell of another array. Convert the inner arrays to values with a function such as
TOROWorTOCOL, or reshape the formula. - A
LAMBDAfunction is entered with no way to run it, or it is called with the wrong number of arguments in some situations. - An array function hit a condition the engine can't handle, such as an input that is too large for it.
When you see #CALC!, check these in order:
- Click the cell and use Formulas > Evaluate Formula. Step through until the first part that returns the error.
- Test the innermost FILTER, TAKE, DROP or SEQUENCE on its own, in a spare cell.
- If it returns a result on its own but not in context, look for a nested array.
Putting it together
Here is a short example that returns the top three sales above 100, or a clear message when there are none. The data is in A2:B20, with names in column A and amounts in column B.
=LET(
big, FILTER(A2:B20, B2:B20>100, ""),
IF(COLUMNS(big)=1, "No sales above 100",
TAKE(SORT(big, 2, -1), 3))
)The steps:
- FILTER keeps the rows above 100, and returns
""if none match. - If
bighas one column, nothing matched, and the formula returns the message. - Otherwise SORT orders the rows by amount, highest first, and TAKE keeps three of them.
- If only two rows matched, TAKE returns two rows. It does not return an error when the data is shorter than the count you requested.
Exercise
A formula =FILTER(A2:C20,C2:C20>100) shows #CALC!. You change it to =SORT(FILTER(A2:C20,C2:C20>100,"None")). What does the cell show when no row matches, and why does the guard go inside SORT's argument rather than around SORT?
Show answer
The cell shows the text None. FILTER's third argument replaces the empty array with a one-cell value, so SORT receives a valid input and sorts it without error. If the guard were only outside SORT (for example in IFERROR), it would also hide unrelated errors. Putting if_empty on the inner FILTER fixes the exact place where the empty array starts.
Exercise
A cell contains =LET(hits,FILTER(A2:C20,C2:C20>100,""),IF(COLUMNS(hits)=1,"No matches",hits)). Why does the width test work, and when would it give a wrong answer?
Show answer
The source range has three columns, so a real result always has three columns. A result with one column can only be the one-cell fallback "", so the test identifies the empty case. It would be wrong if the source range had only one column, because a real result would then also have one column and be mistaken for the fallback. In that case count the matches with SUM(--(condition)) instead.