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

Change colour of icon if a value matches between selected item in gallery, and Collection items

I have a gallery (Gallery1) and a Collection (Collection1).

 

Gallery1 has a list of users with email addresses

 

Collection1 is a table of users who are members of a Group, and each includes their email. 

 

I want to change the colour of an icon, if the selected user in Gallery1 matches an entry in Collection1.

 

I've tried this, but clearly it doesn't work!

 

If(Collection1,Member.email = Gallery1.Selected.Email,Green,Red)
1 ACCEPTED SOLUTION

Accepted Solutions

It looks like your collection has the following structure:

 

Collection1: [{

    Email: [{

        userPrincipalName: ""

    }]

}]

 

You'll want this collection to be flatter, like so:

 

Collection1: [{

    userPrincipalName: ""

}]

 

You should be able to change your function to this, to achieve the desired structure:

ClearCollect(Collection1, AzureAD.GetGroupMembers("6ac59a2e-*****-4f18-******-0f9b52cba5af").value.userPrincipalName)

Lastly, you can update your filter function to:

If(email in Collection1.userPrincipalName, Red, Green)

Let me know if this doesn't work.

View solution in original post

7 REPLIES 7
mabolan
Power Apps
Power Apps

To test if a user is in the collection,  you'll want to use the "in" operator like so,

 

If(email in Collection1.email, Red, Green)

 

 

The above solution should work fine for you. If you want a complete overview of conditional formatting in PowerApps check out the linked video. I show some different things I do in this context to help you learn the basics. 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

Hi both, thanks for the rapid responses. Unfortunately that doesn't seem to work in my app.

 

I have tried this:

 

If('Gallery 1'.Selected.Email  in Collection1.Email,Green,Red)

"Cannot automatically convert this text value into a table" (It highlights the first .Email as the culprit.

Can you confirm that Collection.Email is text? You might be receiving this error if the data in Collection1.Email is a nested table. If possible, could you send a snapshot of your collections table with anonymized emails?

I create the Collection using this:

 

ClearCollect(Collection1, {Email: AzureAD.GetGroupMembers("6ac59a2e-*****-4f18-******-0f9b52cba5af").value.userPrincipalName})

Collection.PNG

 

 

It looks like your collection has the following structure:

 

Collection1: [{

    Email: [{

        userPrincipalName: ""

    }]

}]

 

You'll want this collection to be flatter, like so:

 

Collection1: [{

    userPrincipalName: ""

}]

 

You should be able to change your function to this, to achieve the desired structure:

ClearCollect(Collection1, AzureAD.GetGroupMembers("6ac59a2e-*****-4f18-******-0f9b52cba5af").value.userPrincipalName)

Lastly, you can update your filter function to:

If(email in Collection1.userPrincipalName, Red, Green)

Let me know if this doesn't work.

Perfect - thanks!

Helpful resources

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