cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to perform a Bulk update on a collection based on the id of another collection

I am trying to update a collection where I patch a few rows based on a condition that the id of one collection must match the id of another collection. Here is what I have,

 

ForAll(Filter(Collection1,If(x = 0,true)),Patch(Collection2,LookUp(Collection2,id in Collection1[@id]),{x:0}));

 

So what this command does is return records of collection1 where a field x = 0 holds true and then patches records of collection2 where the id of collection 1 matches with id of collection 2.

 

It patches the first record in Collection2 but does not do for any other records.

I have used "in" operator because the "=" doesn't seem to function in this case.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

 

UpdateContext({FilteredRecords: Filter(Collection1,If(x = 0,true))});

ForAll(FilteredRecords,Patch(Collection2,LookUp(Collection2,id = FilteredRecords[@id]),{x:0}));

 

Strangely the above command seems to work. So instead of doing everything in ForAll, I split it up into two separate commands. The disambiguity operator "@" is important if you want all the records to be updated and not just the first record found by the LookUp function.

 

Refer : https://powerapps.microsoft.com/en-us/blog/bulk-update-using-forall-and-patch/

 

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

 

UpdateContext({FilteredRecords: Filter(Collection1,If(x = 0,true))});

ForAll(FilteredRecords,Patch(Collection2,LookUp(Collection2,id = FilteredRecords[@id]),{x:0}));

 

Strangely the above command seems to work. So instead of doing everything in ForAll, I split it up into two separate commands. The disambiguity operator "@" is important if you want all the records to be updated and not just the first record found by the LookUp function.

 

Refer : https://powerapps.microsoft.com/en-us/blog/bulk-update-using-forall-and-patch/

 

 

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,321)