Showing results for 
Search instead for 
Did you mean: 
Level: Powered On

Add a button that filters gallery

I have a gallery with the following formula:




This works, as i can use the search box to search in the Title en Achternaam columns. I also want to add a button that when people click on it, it returns the gallery items where the InternofExtern column is equal to Intern. I have no idea how i must do this, can somebody help? 

Super User
Super User

Re: Add a button that filters gallery

There are probably several ways to do this but one way is to use UpdateContext() to create a new variable that represents your Gallery items and assign it to the button. I am assuming that you want the gallery to initally show all items and then to have a button filter your list and to be able to toggle between the two options.

1) Set the Screen's OnVisible property to UpdateContext({FilteredList: SortByColumns(Search(Lunchlijst,Zoeken.Text,"Title","Achternaam"),"Achternaam",Ascending),buttonvis: true})

2) Set the Gallery's Items property to FilteredList

3) Add a new button and name it "Intern". Set the button's OnSelect property to: UpdateContext({FilteredList: Filter(SortByColumns(Search Lunchlijst,Zoeken.Text,"Title","Achternaam"),"Achternaam",Ascending),InternofExtern="Intern",buttonvis: false}). Set the button's Visibility property to buttonvis.

4) Add a second button and name it "All".  Set its OnSelect property to UpdateContext({FilteredList: SortByColumns(Search(Lunchlijst,Zoeken.Text,"Title","Achternaam"),"Achternaam",Ascending),buttonvis:true}). Set this button's Visibility property to !buttonvis.

5) Line up the buttons so they exactly overlap. 

Level: Powered On

Re: Add a button that filters gallery

Any ideas?

Super User
Super User

Re: Add a button that filters gallery

Several ways to do this but you can use UpdateContext() to create an alias for your gallery Items property.  I am assuming that you want to toggle the gallery to show all the items and then the filtered items.  I would do as below:

1) Set the screen OnVisible property to UpdateContext({FilterList: SortByColumns(Search(Lunchlijst,Zoeken.Text,"Title","Achternaam"),"Achternaam",Ascending), buttonvis:true})

2) Set the Gallery Items property to FilterList.

2) Add a button and Name it "Interns".  Set its OnSelect property to UpdateContext({FilterList:Filter(SortByColumns(Search(Lunchlijst,Zoeken.Text,"Title","Achternaam"),"Achternaam",Ascending),InternofExtern=Intern),buttonvis:false}). Set the Visibility property of the button to buttonvis.

3) Add a second button and Name it "All". Set its OnSelect property to  UpdateContext({FilterList: SortByColumns(Search(Lunchlijst,Zoeken.Text,"Title","Achternaam"),"Achternaam",Ascending), buttonvis:true}). Set it's Visibility property to !buttonvis.

4) Exactly overlap the two buttons. Let me know if you have any problems.

Level 10

Re: Add a button that filters gallery

Hi @rschalker,


This might be a little easier using a toggle. A toggle has 2 specific states: on or off.

When you use a toggle you cab add an If-statement to your formula to filter or not depending on the state of the toggle.

Since you use the search formula that complicates things a bit because the toggle should act as a filter. 

What you could do is maken an if-statement that specifies when to use the filter option and use your currect search formula as the datasource in your filter. 


Something like this:


			InternofExtern = "Intern"			

Your formula states that the items shown should allways match the search text in Title or Achternaam, but should only be filtered on InternofExtern when the toggle is 'On'. Sorting in both cases is done by Achternaam. 

Level: Powered On

Re: Add a button that filters gallery



Thanks for your answer. I tried step 1, but i get an error. ParentClose is expected, error is found.


UpdateContext({FilterList: SortByColumns(Search(Lunchlijst,Zoeken.Text,"Title","Achternaam"),"Achternaam",Ascending), buttonvis:true})




Community Support Team
Community Support Team

Re: Add a button that filters gallery

Hi Rschalker,


Have you tried the suggestion posted by @Rebetcha?


Using a toggle or checkBox should be better to control the items within the gallery.


Besides, for the error messages, would you please share a screenshot for it?

The formula posted should be able to work with the two variables.

Adding the function reference:

UpdateContext function in PowerApps





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

Re: Add a button that filters gallery

The key is to create an alias for the items in your gallery and then filter the alias.  I agree that using a toggle be easier than using two buttons but your question indicated a preference for a button. I tested this using one of my own galleries and it worked for me. 

Add two buttons to the screen outside of the gallery, Name one "All" and the other "Intern".

Set the OnSelect of the first button to UpdateContext({ds:  Lunchlijst}) and  the second to UpdateContext({ds: Filter(Lunchlijst,InternofExtern="Intern")}) . 

Change your Gallery's Items property to SortByColumns(Search(ds,Zoeken.Text,"Title","Achternaam"),"Achternaam",Ascending)

To have the Gallery show all of the items unfiltered when the screen becomes visible, set the screen's OnVisible property to UpdateContext({ds:  Lunchlijst})

Helpful resources

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.


Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!


Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020


Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.


Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

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