#PowerPlatformTip 62: 'UpdateIf'
TL;DR: Use
UpdateIfto update records that match a condition. With a local collection it updates the in-memory records; data-source delegation depends on the connector and formula.
💡 Challenge
Updating selected records with separate formulas can be cumbersome. UpdateIf applies a condition and change record to the matching rows of a collection or data source.
✅ Solution
Use UpdateIf to target records that meet a condition. For a collection, it changes the matching records in memory. When the first argument is a data source, check its delegation support before relying on it for rows beyond the app’s data row limit.
🔧 How It’s Done
1. Define your collection
🔸 Ensure fields like Age (number) and Status (text) exist in your collection.
2. Apply the UpdateIf function
🔸 Use UpdateIf(MyCollection, Age > 30, {Status: "Senior"}) to update matching records in a collection.
3. Verify data types
🔸 Make sure the field types and value types align to avoid runtime errors.
🎉 Result
Matching collection records have their Status set to Senior. The formula avoids writing a separate ForAll loop for this collection update.
🌟 Key Advantages
🔸 Flexibility: Modify only the records that match specific conditions
🔸 Fewer repeated formulas for a collection update
🔸 Clear condition and change record
🛠️ FAQ
Q: What happens if no records meet the criteria?
UpdateIf leaves the collection unchanged when no records match the condition.
Q: Can I update multiple fields at once?
Yes. Pass multiple field-value pairs in the record argument, e.g. UpdateIf(MyCollection, Condition, {Status: "Senior", Active: true}).
Q: Does UpdateIf modify the original collection?
Yes. UpdateIf directly updates the existing collection in memory rather than creating a new one.
🔗 Related Tips
🔸 #PowerPlatformTip 57: ‘Mastering PATCH’ - the function to reach for when you need to update or insert an entire table at once, not just matching records.
🔸 #PowerPlatformTip 81: ‘Fast DataSource Updates’ - more bulk-update techniques for large data sets.
This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).