cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
landonjochim
Resolver I
Resolver I

How to filter based on one of the items in a record column being in another collections record column

I have a Variable (varFunction) which has a record column (roles) and a collection of users (colHeritageManagement) who also have a record column (Roles). I want to get a list of the users from colHeritageManagement that's Roles column contains one of the results from Roles column from varFunction.

 

Below is what I have currently and I cannot seem to get this figured out. I am not getting any errors, but the items in the Gallery are not correct. Seem to have the columns but no data is coming in.

 

ForAll(varFunction.roles.Result As _role, Filter(colHeritageManagement As _user, _role.Result in _user.Roles.Value))

 

varFunction Variable: Want to search the collection for any items that Role column contain either "Administrative Tasks" or "Talent Management"

landonjochim_0-1637006494857.png

landonjochim_1-1637006523972.png

 

landonjochim_2-1637006725518.png

landonjochim_4-1637006815582.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

This took me quite awhile and looking at multiple posts. The issue was I kept using a ForAll because I wanted to see if any of the varFunction.roles.Results were inside each colHertiageManagement.Roles.Values. And the ForAll would not return a true/false result to show that user in the Gallery.

The CountIf solved this for me. Here is the post that helped https://powerusers.microsoft.com/t5/Building-Power-Apps/Breaking-from-ForAll-loop-or-using-set-insid... 

 

Here is the working formula:

Filter(colHeritageManagement, If(CountIf(Roles, Value in varFunction.roles.Result)>0,true,false))

 

View solution in original post

4 REPLIES 4
WarrenBelz
Super User
Super User

Hi @landonjochim ,

Are you trying to create another collection or filter a gallery?

For a Collection

ClearCollect(
   colFiltered,
   Filter(
      colHeritageManagement,
      Result in varFunction.Roles.Value
   )
)

gallery Items would simply be

Filter(
   colHeritageManagement,
   Result in varFunction.Roles.Value
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

I am filtering a gallery. Couple things from your reply; Result is not a valid identifier where you placed it. Also, varFunction.roles cannot be .Value, but .Result only.

landonjochim_0-1637071835416.png

 

This took me quite awhile and looking at multiple posts. The issue was I kept using a ForAll because I wanted to see if any of the varFunction.roles.Results were inside each colHertiageManagement.Roles.Values. And the ForAll would not return a true/false result to show that user in the Gallery.

The CountIf solved this for me. Here is the post that helped https://powerusers.microsoft.com/t5/Building-Power-Apps/Breaking-from-ForAll-loop-or-using-set-insid... 

 

Here is the working formula:

Filter(colHeritageManagement, If(CountIf(Roles, Value in varFunction.roles.Result)>0,true,false))

 

View solution in original post

@landonjochim ,

I was going off the values you posted when I responded - glad you got it sorted.

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

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