cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

Want to compare two collections

Hello experts,

 

I want to compare two collections. first collection have user Role matrix, and second collection has Current logged in user groups.

 

Role Matrix

RoleBasedMatrix.jpg

 

Current User Groups

 

Current User GroupsCurrent User Groups

 

I want to compare Current User Group collection with Role Matrix role column, means want to get list of all roles which current user having in second collection.

 

how can i achieve this, please help!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Resolver III
Resolver III

Hi @sachinsoni 
Not sure how big each time both collections will be... My suggestion can be considered as the not the top performance idea.

But if this is not big chunk of data you can use ForAll function and nest it:)
Created two collections based on the information from you:

Collect(colRole,{role:"Business Development"},{role:"Legal"},{role:"Vice President"},{role:"President"});
Collect(colCurrentUserGroups,{displayname:"DevCompetentialDigital"},{displayname:"Business Development"})

And then applied:

ForAll(colRole,ForAll(colCurrentUserGroups,If(displayname=role,Collect(colMatch,{matchFound:displayname}))))

 

Result:

Forum1.png


I used the Collect for the match pair but you can do other actions:)

Hope this will solve your problem if yes please mark it as solution:)
Regards

View solution in original post

13 REPLIES 13
Highlighted
Super User
Super User

You can use the Filter() and 'in' syntax to do that. It would look like this

Filter(RoleMatrix,role in 'Current User Groups'.displayName)

---
If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up. 

Highlighted
Resolver III
Resolver III

Hi @sachinsoni 
Not sure how big each time both collections will be... My suggestion can be considered as the not the top performance idea.

But if this is not big chunk of data you can use ForAll function and nest it:)
Created two collections based on the information from you:

Collect(colRole,{role:"Business Development"},{role:"Legal"},{role:"Vice President"},{role:"President"});
Collect(colCurrentUserGroups,{displayname:"DevCompetentialDigital"},{displayname:"Business Development"})

And then applied:

ForAll(colRole,ForAll(colCurrentUserGroups,If(displayname=role,Collect(colMatch,{matchFound:displayname}))))

 

Result:

Forum1.png


I used the Collect for the match pair but you can do other actions:)

Hope this will solve your problem if yes please mark it as solution:)
Regards

View solution in original post

Highlighted

Many thanks,

Then how can i get complete record item instead of role column.

Highlighted

My Filter() solution above would return all columns in the 'Role Matrix' collection where the values match the displayName column in the 'Current User Groups' collection.

---
If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up.

Highlighted

@EricLott @365CornerDawid Is it possible that, if groups is match then can i hide or show any button.

Highlighted

@sachinsoni 

Probably, can you give an example? Like you want to hide a button if the user is not in a specific group?

Highlighted

Yes, exactly. I have role wise buttons on my screen Like Business Development, President, Vice President and legal, i want if user present in respective group, then only respective button will be show.

Highlighted

The previous question about capturing the whole record would require to apply changes to the column / filed ID of one collection and renaming it to ID2 or something similar. That would allow you to capture the whole record using ID. 

As for the second question based on the comparison result you could go with something like:

Set(varGroupCheck,IsEmpty(colMatch))

And then connect varGroupCheck with the visible property of your controls 🙂

Highlighted

@sachinsoni 
The previous answer will be only valid for the general fact that match was found so please ignore my answer:P 

If there is only one possible result then much easier it will be move forward with the Filter option. I had in mind that more than one match can be found during comparison.

So the last bit what you would need to think is set the proper conditions. When you will capture what role you have in current session connect variable or result with the visible control to say something like:
varRole="President" (you dont need to write if as it will return true or false)

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (8,172)