cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AmDev
Super User
Super User

ForAll filtering a collection based on column in other collection

Hi

 

I'm hoping someone can give me a steer - I'm pretty sure this is simple, but I have made it difficult 😕

 

I have built an app and am currently trying to complete the last element. I'm stuck on trying to shape/filter my collection within a ForAll step, which passes each batch of filtered data as an input parameter to a flow. I'm OK with the flow / passing the parameters/JSON etc and had this all working fine. It's just now when I try to compile and pass more input parameters, I'm struggling with the shaping of this added data etc.

 

In the app, users can select multiple recipients from multiple orgs and in doing so create a collection (Collection1) like the following:

OrgUser
Org1UserA
Org1UserB
Org2UserC
Org2UserD
Org2UserE

 

As part of my flow, I want to pass the details for each org as a separate run i.e. Flow run 1 for just Org 1 users, Flow run 2 for just Org 2 users etc etc

 

I 'thought' the easy way to shape the data like that was to create a distinct collection of the Orgs (Collection2) and use this as the source in a Forall action, which would loop through each org and filter Collection1 based on the current value in the ForAll loop. Using the distinct function, Collection2 looks like this:

 

Result
Org1
Org2

 

Though, when I try to do this I cannot seem to get 'ThisRecord.Result' in the ForAll source loop to present inside the filter function within my ForAll. ThisRecord inside the Filter loop defaults to ThisRecord of Collection1 instead of Collection2

 

Any advice would be much appreciated.

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@AmDev 

Sounds like you need to consider GroupBy instead of distinct.

Consider the following:

ForAll(GroupBy(yourCollection, "Org", "_recs"),
    yourFlow.Run(JSON(_recs))
)

Of course, the above completely hypothetical based on what you mention in the post, but the concept is, Group the collection by the Org.  The _recs column result will then have all of the Users for that Org in it.  So, you are just simply referencing the _recs table to get what you need.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

3 REPLIES 3
RandyHayes
Super User
Super User

@AmDev 

Sounds like you need to consider GroupBy instead of distinct.

Consider the following:

ForAll(GroupBy(yourCollection, "Org", "_recs"),
    yourFlow.Run(JSON(_recs))
)

Of course, the above completely hypothetical based on what you mention in the post, but the concept is, Group the collection by the Org.  The _recs column result will then have all of the Users for that Org in it.  So, you are just simply referencing the _recs table to get what you need.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes  - Perfect, many thanks for this. Exactly what I needed (along with some free education on the groupby function.. 👍)

RandyHayes
Super User
Super User

@AmDev 

Always happy to help!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,428)