Pro Tip – How to use UpdateIf() in Canvas App

By | October 16, 2023

Let us explore the use and functionalities of the UpdateIf() Function using some simple examples.

Requirements

Suppose, we have created a data table in our canvas app, where we have some records. We have created an option set field on the Account form with the name ‘Preference’ where we have different options i.e. Basic, Premium, etc. We need to set Premium as the value of the preference field for the records that have annual revenue of more than $5,000,000. The value for preference should be set for all records present in the table at the click of a button.

To achieve the above customer requirement, we have created a Canvas App and tried to implement it using the UpdateIf() Function.

UpdateIf Function

To change one or more values in one or more records that match one or more conditions, use the UpdateIf function. Any formula that returns a true or false result can be used as the condition, and it can explicitly refer to specific columns in the data source. Each record’s condition is evaluated by the function which updates any records for which the result is true. UpdateIf, return a table using the changed data source.

Syntax

UpdateIf( DataSource, Condition1, ChangeRecord1 [, Condition2, ChangeRecord2, ….])

  • DataSource – Required. The source of the record or records to be modified is required.
  • Condition(s) – Required. A formula that, when applied to the record or records you want to change, returns true. The formula can use the Data Source’s column names.
  • ChangeRecord(s) – Required. A change record of new property values to be applied to DataSource records that meet the condition is created for each corresponding condition. The property values of the existing record can be used in the property formulas if you provide the record inline using curly braces.

To achieve this requirement, we have added one button in the canvas app and entered the following code in its OnSelect property:

UpdateIf(Accounts, ‘Annual Revenue’ >= 5000000, {Preference:’Preference(Accounts)’.Premium})

Canvas App

After saving the above changes we must click the update button for the above-mentioned formula to execute, then the preference field will be set as Premium for all the records present in the data table that have an Annual Revenue of more than $5,000,000.

Canvas App

Conclusion

The UpdateIf() function provides new options for the PowerApps formula in Dynamics 365. Users can easily update the record’s data based on the desired conditions by executing a simple powerFX formula instead of writing a script or doing some lengthy workaround to achieve the requirement. This opens new options for the canvas apps since it relies mostly on the powerFX formula.

Canvas App