IFERROR (Value, FallbackValue) IFERROR (Value; FallbackValue)

Value

The value to return if it is not an error.

FallbackValue

The value to return if the value parameter is an error.

Returns

The first parameter if it is not an error and the second parameter otherwise.

Returns a value unchanged if it is not an error and a different value otherwise. IFERROR (Value1 / 0, 10) IFERROR (Value1 / 0; 10) always returns 10 (because dividing a number by zero results in an error).

There are different types of errors. To learn the exact error type, use ERROR.TYPE. To determine if a value is an error, use ISERROR.

#N/A errors

Lookup functions like XLOOKUP return #N/A errors ("not available") when a value cannot be found. The ISNA function may be used to detect the #N/A error specifically.

This formula returns TRUE, because the sought value, 10, is not part of the { 20, 30 }{ 20; 30 } lookup array given to XLOOKUP:

ISNA ( XLOOKUP (10, { 20, 30 }, { 200, 300 }))
ISNA ( XLOOKUP (10; { 20; 30 }; { 200; 300 }))

The IFNA function is used to return a specific value if a value is an #N/A error, or the value itself otherwise. This formula returns 500, because the sought value, 10, is not part of the { 20, 30 }{ 20; 30 } lookup array given to XLOOKUP:

IFNA ( XLOOKUP (10, { 20, 30 }, { 200, 300 }), 500)
IFNA ( XLOOKUP (10; { 20; 30 }; { 200; 300 }); 500)

ISERR is the opposite of ISNA, meaning that it detects all errors except for #N/A errors. Consider this formula:

ISERR ( XLOOKUP (Value1 / Value2, { 20, 30 }, { 200, 300 }))
ISERR ( XLOOKUP (Value1 / Value2; { 20; 30 }; { 200; 300 }))

The formula above returns TRUE if Value2 is 0 or blank, resulting in a #DIV/0! error ("division by zero"), but it returns FALSE if the value resulting from the Value1 / Value2Value1 / Value2 cannot be found in the lookup array.

Unlike IFNA, IFERROR detects all errors. If the intent is to detect #N/A errors specifically, using IFERROR is a mistake.

For an example of why using IFERROR instead of IFNA can be a mistake, consider this formula:

IFERROR ( XLOOKUP (Value1 / Value2, { 20, 30 }, { 200, 300 }), 500)
IFERROR ( XLOOKUP (Value1 / Value2; { 20; 30 }; { 200; 300 }); 500)

If Value2 is zero, or is blank, this will cause a #DIV/0! ("division by zero") error to be returned from the / operator, which XLOOKUP will pass on to IFERROR, which in turn will cause IFERROR to return 500 instead of the #DIV/0! error.

If the intent is to only return 500 if the sought value cannot be found in the lookup array, it is better to use the formula IFNA ( XLOOKUP (10, { 20, 30 }, { 200, 300 }), 500) IFNA ( XLOOKUP (10; { 20; 30 }; { 200; 300 }); 500) and let the #DIV/0! error slip past IFNA.

IFERROR and arrays

Applying IFERROR to an array yields an array with the same size as the original array, where errors are replaced with the second parameter and all other elements are returned unchanged.

This formula returns the array { 1, 2, - 1, 4 }{ 1; 2; - 1; 4 }, as the third array element is an #N/A error:

IFERROR ({ 1, 2, NA (), 4 }, - 1)
IFERROR ({ 1; 2; NA (); 4 }; - 1)

If the array is itself an error, IFERROR returns an array with a single element. This formula returns the array { 99 }{ 99 }, as the GROWTH function returns an error on account of the two arrays not being equal in size:

IFERROR ( GROWTH ({ 1 }, { 1, 2 }), 99)
IFERROR ( GROWTH ({ 1 }; { 1; 2 }); 99)

An empty array contains no errors. FILTER returns an empty array when no values match, so IFERROR cannot be used to detect that case. Give FILTER a third parameter instead, which it returns when no values match. This formula returns {  - 50 }{  - 50 }:

FILTER ({ 10, 20, 35 }, Element > 50, {  - 50 })
FILTER ({ 10; 20; 35 }; Element > 50; {  - 50 })

Examples

IFERROR (Value1 / Value2, 0)
IFERROR (Value1 / Value2; 0)

Returns the result of dividing Value1 by Value2 if there is no error, and 0 otherwise.

IFERROR (Value1 / Value2, BLANK ())
IFERROR (Value1 / Value2; BLANK ())

Returns the result of dividing Value1 by Value2 if there is no error, and a blank value otherwise.

IFERROR ( XLOOKUP (10, { 20, 30 }, { 200, 300 }), 500)
IFERROR ( XLOOKUP (10; { 20; 30 }; { 200; 300 }); 500)

Returns 500, because the sought value, 10, is not part of the { 20, 30 }{ 20; 30 } lookup array given to XLOOKUP. IFERROR catches all errors, though, not just the #N/A error returned from XLOOKUP when it cannot find a value.

IFNA ( XLOOKUP (10, { 20, 30 }, { 200, 300 }), 500)
IFNA ( XLOOKUP (10; { 20; 30 }; { 200; 300 }); 500)

Returns 500, because the sought value, 10, is not part of the { 20, 30 }{ 20; 30 } lookup array given to XLOOKUP. The IFNA function catches only #N/A errors, unlike IFERROR, which catches all errors. If the intent is to only return 500 if the value cannot be found, it is better to use IFNA.

IFERROR ( GROWTH ({ 1 }, { 1, 2 }), 99)
IFERROR ( GROWTH ({ 1 }; { 1; 2 }); 99)

Returns the array { 99 }{ 99 }, as the GROWTH function returns an error on account of the two arrays not being equal in size.

IFERROR ({ 1, 2, NA (), 4 }, - 1)
IFERROR ({ 1; 2; NA (); 4 }; - 1)

Returns the array { 1, 2, - 1, 4 }{ 1; 2; - 1; 4 }. All array elements are returned unchanged, except for the third array element. That element is an #N/A error, and is replaced with -1.

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell