Latest Posts

PowerApps Update record based on condition


The UpdateIf function in PowerApps is used to update one or more records in a data source based on a condition. This function allows you to selectively update records that meet specific criteria, making it useful for scenarios where you need to modify multiple records dynamically.

PowerApps – UpdateIf() function Syntax

 

UpdateIf(DataSource, Condition, ChangeRecord1 [, ChangeRecord2, ...])

 

  • DataSource: The data source that contains the records you want to update.
  • Condition: The condition that determines which records to update. This is typically an expression that evaluates to true for the records that should be updated.
  • ChangeRecord1, ChangeRecord2, ...: One or more records that specify the fields to update and their new values.

Notes:

  • No Matching Records: If no records match the condition, UpdateIf does nothing. Ensure that the condition is correctly specified.
  • Partial Updates: Fields not specified in the ChangeRecord remain unchanged. Ensure you specify all necessary fields in the update record.
  • Bulk Updates: When updating multiple records, ensure that the update operation is efficient to avoid performance issues. Using UpdateIf is generally efficient, but test with your specific data set.
  • Network Latency: If working with remote data sources, be mindful of network latency. Minimize the number of updates where possible to maintain app responsiveness.

PowerApps – UpdateIf() Basic Example

Suppose you have a data source named Employees and you want to update the Status field to "Active" for all employees in the "Sales" department:

 

UpdateIf(Employees, Department = "Sales", { Status: "Active" })

 

This updates the Status field to "Active" for all records in the Employees data source where the Department is "Sales".

PowerApps – Update multiple fileds using UpdateIf() function

To update multiple fields for the same condition, specify the changes in a single record:

 

 

UpdateIf(Employees, Department = "Sales", { Status: "Active", Bonus: 1000 })

 

This updates the Status field to "Active" and sets the Bonus field to 1000 for all records where the Department is "Sales".

PowerApps – Complex UpdateIf() Condition example

Suppose you want to update the Status field to "Inactive" for all employees who have not logged in for over a year:

 

 

UpdateIf(Employees, DateDiff(LastLoginDate, Today(), Days) > 365, { Status: "Inactive" })

 

This sets the Status field to "Inactive" for all records where the number of days since the LastLoginDate is greater than 365.

 


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint