IFERRORIFERROR

如果表达式返回错误,则会对表达式进行求值并返回指定的值;否则会返回表达式本身的值。Evaluates an expression and returns a specified value if the expression returns an error; otherwise returns the value of the expression itself.

语法Syntax

IFERROR(value, value_if_error)  

parametersParameters

术语Term 定义Definition
value 任何值或表达式。Any value or expression.
value_if_errorvalue_if_error 任何值或表达式。Any value or expression.

返回值Return value

与 value 同类型的标量 A scalar of the same type as value

备注Remarks

可以使用 IFERROR 函数来捕获和处理表达式中的错误。You can use the IFERROR function to trap and handle errors in an expression.

如果 value 或 value_if_error 为空单元格,IFERROR 则会将其视为空字符串值 ("") 。If value or value_if_error is an empty cell, IFERROR treats it as an empty string value ("").

IFERROR 函数基于 IF 函数,并且使用相同的错误消息,但拥有的参数更少。The IFERROR function is based on the IF function, and uses the same error messages, but has fewer arguments. IFERROR 函数和 IF 函数之间的关系如下所示:The relationship between the IFERROR function and the IF function as follows:

IFERROR(A,B) := IF(ISERROR(A), B, A)

请注意,为 A 和 B 返回的值必须属于相同的数据类型;因此,用于 value 的列或表达式与为 value_if_error 返回的值必须是相同的数据类型 。Note that the values that are returned for A and B must be of the same data type; therefore, the column or expression used for value and the value returned for value_if_error must be the same data type.

示例Example

如果对表达式 25/0 的计算得到错误,下面的示例则会返回 9999。The following example returns 9999 if the expression 25/0 evaluates to an error. 如果表达式返回 error 以外的值,该值则会传递给调用表达式。If the expression returns a value other than error, that value is passed to the invoking expression.

=IFERROR(25/0,9999)  

另请参阅See also

逻辑函数 (DAX)Logical functions (DAX)