Showing results for 
Search instead for 
Did you mean: 
Not applicable

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 II
Super User II

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. 

Not applicable

Any ideas?

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.


Hi @Anonymous,


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. 

Not applicable



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})




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.

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

PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group


Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (17,907)