cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kcgov
Frequent Visitor

Filter Gallery with Buttons using Option Sets

Hi,

 

I've read through countless topics here to try to figure out how to display all of the items in a gallery pressing a button but still could not get it to work correctly. I'm new to Powerapps and trying to recreate an app for my job so I'm probably missing something simple.

 

Issue: 

Trying to filter a gallery from a CDS datasource using the following buttons: All, Open, Pending, Approved, Declined. The buttons are from an option set and when pressed should display items that match the status of the button pressed. I'm able to filter the gallery using every button except the All button. I would like the All button to display all items (Open, Pending, Approved, Declined) in the Gallery.

 

Here's what I have:

Buttons - UpdateContext({cFilter:'Status'.Open}), UpdateContext({cFilter:'Status'.Pending}), etc

Gallery - Filter(CASES, 'Status' = cFilter)

 

I've tried a number of different ways to display all of the items in the Gallery by clicking the All button but nothing worked. When I did get it to work the gallery wouldn't change when clicking the other buttons. 

 

Any help with this is appreciated. Thanks for reading!

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @kcgov ,

Do you want to filter your Gallery Items based on the Buttons click against the Option Set Type column in your CDS Entity?

 

Based on the formula that you mentioned, I think there is something wrong with it. I have made a test on my side, please try the following workaround:

Set the OnSelect property of "All" button to following:

Set(CurrStatus, "All")

Set the OnSelect property of "Open" button to following:

Set(CurrStatus, "Open")

Set the OnSelect property of "Pending" button to following:

Set(CurrStatus, "Pending")

Set the OnSelect property of "Approved" button to following:

 

Set(CurrStatus, "Approved")

 

Set the OnSelect property of "Declined" button to following:

Set(CurrStatus, "Declined")

 

Set the Items property of the Gallery to following:

Filter(
       CASES,
       If(
          CurrStatus = "All" || IsBlank(CurrStatus),
          true,
          CurrStatus = "Open",
          Status = [@StatusOptionSetName].Open,
          CurrStatus = "Pending",
          Status = [@StatusOptionSetName].Pending,
          CurrStatus = "Approved",
          Status = [@StatusOptionSetName].Approved,
          CurrStatus = "Declined",
          Status = [@StatusOptionSetName].Declined
       ) 
)

Note: The StatusOptionSetName represents the OptionSet name your Option Set column related to, please replace it with your own Option Set Name from your CDS.

 

Please check and see if the following blog would help in your scenario:

https://powerapps.microsoft.com/en-us/blog/option-sets-and-many-to-many-relationships-for-canvas-app...

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Drrickryp
Super User
Super User

Hi @kcgov 

Have your context variable create the entire filter instead of just the status part.

 

 UpdateContext({itemvar:Filter(Cases,'Status'.Open)})
 UpdateContext({itemvar:Filter(Cases, 'Status'.Pending)}), etc

 

For the All button UpdateContext(itemvar:Cases}).  Set the Items property of the gallery to Itemvar

and set the OnVisible property of the screen to UpdateContext(itemvar:Cases}) as the default for the Gallery so it will show all the cases without a filter. BTW itemvar is just an arbitrary name for the context variable, it could be anything you want.

kcgov
Frequent Visitor

Thanks for the quick reply! Although all of the gallery items appeared by default, unfortunately, selecting the button to filter the gallery did not work. I received errors from the name being invalid to the function 'Filter' having invalid arguments. As a quick test this is what I did:

 

Open.OnSelect: UpdateContext({cFilter:Filter(CASES,'Case Status'.Open)})

Items.Gallery: cFilter

OnVisible.Screen: UpdateContext({cFilter:CASES})

Hi @kcgov 

Take a look at this blog about filtering with option sets. https://michalguzowski.pl/how-to-work-with-option-set-in-powerapps/  to develop the correct syntax for your filter.  I think that is the problem.

v-xida-msft
Community Support
Community Support

Hi @kcgov ,

Do you want to filter your Gallery Items based on the Buttons click against the Option Set Type column in your CDS Entity?

 

Based on the formula that you mentioned, I think there is something wrong with it. I have made a test on my side, please try the following workaround:

Set the OnSelect property of "All" button to following:

Set(CurrStatus, "All")

Set the OnSelect property of "Open" button to following:

Set(CurrStatus, "Open")

Set the OnSelect property of "Pending" button to following:

Set(CurrStatus, "Pending")

Set the OnSelect property of "Approved" button to following:

 

Set(CurrStatus, "Approved")

 

Set the OnSelect property of "Declined" button to following:

Set(CurrStatus, "Declined")

 

Set the Items property of the Gallery to following:

Filter(
       CASES,
       If(
          CurrStatus = "All" || IsBlank(CurrStatus),
          true,
          CurrStatus = "Open",
          Status = [@StatusOptionSetName].Open,
          CurrStatus = "Pending",
          Status = [@StatusOptionSetName].Pending,
          CurrStatus = "Approved",
          Status = [@StatusOptionSetName].Approved,
          CurrStatus = "Declined",
          Status = [@StatusOptionSetName].Declined
       ) 
)

Note: The StatusOptionSetName represents the OptionSet name your Option Set column related to, please replace it with your own Option Set Name from your CDS.

 

Please check and see if the following blog would help in your scenario:

https://powerapps.microsoft.com/en-us/blog/option-sets-and-many-to-many-relationships-for-canvas-app...

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Thank you for the reply! I will try it out in the morning and provide an update.

v-xida-msft
Community Support
Community Support

Hi @kcgov ,

Sure. Please take a try with the solution I provided, check if the issue is solved. If you have some issues with it, please feel free to let me know here.

 

Regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-xida-msft,

 

Your solution worked, thank you! 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,940)