The IfError function in Power Apps is used to handle errors in expressions and return a specified result if an error occurs.
If the function finds an error, the function evaluates and returns a corresponding replacement value and stops further evaluation.
Use IfError to replace an error with a valid value so that downstream calculations can continue.
IfError(Value, Replacement)
- Value: The expression or formula that might produce an error.
- Replacement: The value or action to take if the Value results in an error.
If the Value evaluates successfully without error, IfError will return the result of the expression.
If the Value results in an error, IfError will return the Replacement value.
Usages of IfError function
Example 1: Handling division by zero in an expression
Below formula uses the IfError function to handle potential errors in a division operation, particularly focusing on the case of dividing by zero.
IfError( Â 100 / TextInput1.Text, Â "Error: Division by zero" )

If the user enters 0 or any non-numeric value in TextInput1, the formula will trigger an error, and instead of the app breaking, it will display the message “Error: Division by zero”.

Example 2: Validate inputs
If you are converting a text value to a number and need to handle invalid inputs, you can use the IfError function to handle any errors that occur.
IfError( Â Value(TextInput1.Text), Â 0 )

Example 3: Handling error during Patches
You can use the IfError function to handle errors across multiple Patch functions or when performing multiple data operations.
This is useful when you need to ensure that the app gracefully handles any potential errors during these operations, such as saving records to a data source.
Let’s say you are patching data to multiple data sources such as Emp1 and Emp2 and you want to handle errors for both patches separately and provide meaningful feedback if any of them fail.
IfError(
Patch(Emp1, Defaults(Emp1), {empname: txt_empname.Text, address: txt_address.Text, salary: txt_salary.Text}),
Notify("Error occurred for Emp1 records", NotificationType.Error),
Patch(Emp2, Defaults(Emp2), {empname: txt_empname.Text, address: txt_address.Text, salary: txt_salary.Text}),
Notify("Error occurred for Emp2 records", NotificationType.Error),
Notify("Records saved successfully!", NotificationType.Success)
)
The IfError function checks for errors in each Patch function sequentially. If an error occurs in either one, it immediately executes the corresponding error message and stops further execution.
The Notify function is used to provide immediate feedback to the user. It shows messages based on the success or failure of the operations.
If all Patch functions succeed without errors, the success message is displayed.
When to user IfError function
Use the IfError function in Power Apps whenever you need to:
- Manage potential errors in data operations, calculations, or expressions.
- Ensuring your app continues to function smoothly without crashing due to runtime issues.
- Display user-friendly messages or take alternative actions when errors occur.
Also Read..
![]()
