cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
patrick1992
Level: Powered On

Compare two collections and set certain records to true

I have two records that are similar to one another:

 

lk_collection

task_id | task_selected

1              false

2              false

3              false

 

4              false

5              false

6              false

7              false

8              false

9              false

 

selected_collection

task_id | task_selected

1                    true

5                    true

9                    true

 

I want to be able to set the task_selected in lk_collection  to true if their task_id appears in selected_collection

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Compare two collections and set certain records to true

You could use the the ForAll function to loop through the selected_collection and update the lk_collection. The code would look something like this:

 

ForAll(RenameColumns(selected_collection,"task_id", "task_id1"), 
  Patch(lk_collection, LookUp(lk_collection, Text(task_id) in Text(task_id1)),{task_selected:true}))

I had to use the RenameColumn function to rename the selected_collection task_id in memory (doesn't affect the actual collection) because it was conflicting with the lk_collection task_id.

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
2 REPLIES 2
Super User
Super User

Re: Compare two collections and set certain records to true

You could use the the ForAll function to loop through the selected_collection and update the lk_collection. The code would look something like this:

 

ForAll(RenameColumns(selected_collection,"task_id", "task_id1"), 
  Patch(lk_collection, LookUp(lk_collection, Text(task_id) in Text(task_id1)),{task_selected:true}))

I had to use the RenameColumn function to rename the selected_collection task_id in memory (doesn't affect the actual collection) because it was conflicting with the lk_collection task_id.

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
AnnaCICI_Z
Level: Powered On

Re: Compare two collections and set certain records to true

Hi Jeff,

 

I use the your code, but it changes just the first item in lk_collection.

Maybe I should do something else before this code ?

 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 73 members 4,247 guests
Please welcome our newest community members: