IfError function in PowerApps
Detects errors and provides an alternative value or takes action.
This function is part of an experimental feature and is subject to change. The behavior described here is only available when the Formula-level error management feature is turned on. This is an app level setting that defaults to off. To turn this feature on, navigate to the File tab, App settings in the left hand menu, and then Experimental features. Your feedback is very valuable to us - please let us know what you think in the PowerApps community forums.
The IfError function tests each of its arguments in order for an error value, stopping when the first non-error value is found. The arguments after the non-error value is found are ignored and not evaluated.
Use IfError to replace error values with a valid value. For example, if it is possible that user input may result in a division by zero, replace it with a 0 or other valid value that is appropriate for your app so that downstream calculations can proceed.
If all of the arguments to IfError result in an error, the value of the last argument is returned (which will be an error value).
IfError( Value, Fallback1 [, Fallback2, ... ] )
- Value - Required. Formula(s) to test for an error value.
- Fallback(s) - Required. The formulas to evaluate and values to return if previous arguments returned an error. Fallback arguments are evaluated in order up to the point a a non-error value is found.
|IfError( 1, 2 )||The first argument is not an error. It is returned and subsequent arguments are not evaluated.||1|
|IfError( 1/0, 2 )||The first argument is returning an error value (due to division by zero). The second argument is evaluated resulting in a non-error value which is returned.||2|
|IfError( 1/0, Notify( "There was an internal problem", NotificationType.Error ) )||The first argument is returning an error value (due to division by zero). The second argument is evaluated which displays a messages to the user. The return value of IfError is the return value of Notify, coerced to the same type as the first argument to IfError (a number).||1|
|IfError( 1/0, 1/0, 2, 1/0, 3 )||The first argument is returning an error value (due to division by zero). The second argument is evaluated, also resulting in an error value (another division by zero). The third argument is evaluated, which does not return in an error value which is returned. The fourth and fifth arguments are ignored.||2|
Step by step
Add a Text input control, and name it TextInput1 if it doesn't have that name by default.
Add a Label control, and name it Label1 if it doesn't have that name by default.
Set the formula for Label1's Text property to:
IfError( Value( TextInput1.Text ), -1 )
In TextInput1, type 1234.
Label1 will show the value 1234 as this is a valid input to the Value function.
In TextInput1, type ToInfinity.
Label1 will show the value -1 as this is not a valid input to the Value function. Without wrapping the Value function with IfError, the label would show no value as the error value is treated as a blank.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.