web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Creating a filter on a...
Power Apps
Answered

Creating a filter on a gallery based on a toggle value yes/no

(0) ShareShare
ReportReport
Posted on by 580

Hi All,

 

Recently I tried to create a filtered gallery using additional screens, additional galleries and I think I over complicated the issue by accident, @RandyHayes helped me find the solution to the issue but looking back, this could have been made a lot simpler by just using one screen.

So I'm going to try another approach, I have a PowerApp which is a staff database, I have the usual screens BrowseScreen1, DetailScreen1 ect. 

 

On the BrowseGallery1 screen, I want to add filter buttons at the top which will filter the records depending on which button is active and according to a toggle value set within the record of yes / no (true / false)

2021-02-13 10_14_23-NC MST Tracker V1 - Saved (Unpublished) - Power Apps.png

 

The picture below is the Fields and Toggle values within a staff members record

2021-02-13 10_13_54-NC MST Tracker V1 - Saved (Unpublished) - Power Apps.png

This is the code I am using so far:

2021-02-13 10_14_48-NC MST Tracker V1 - Saved (Unpublished) - Power Apps.png

The part I'm struggling with is the code to use, for example:
If either the "MST" "AET" "MENTOR" button is selected, filter the gallery based on the toggle values (true / false) within the records. 

 

Anyone with experience around this?

 

Many Thanks 🙂 

Categories:
I have the same question (0)
  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @AdamH 

    I approached the problem by creating a context variable for the buttons and used it as the Items property of the gallery. I used my list of fictitious contacts as an example. In the screenshot, the OnVisible property of the screen sets the default property of the gallery to show all of the items unfiltered.

     

    UpdateContext(
     {
     itms: Filter(
     FakeNames,
     StartsWith(
     company_name,
     TextSearchBox1.Text
     )
     )
     }
    )

     

    The OnSelect property of buttons each contain a context variable (itms) that is either unfiltered (All) as is shown below the All button or filtered by state as shown below the TX button. 

    The gallery contains the context variable sorted by company and city. In this particular example, the gallery is sorted based on the "CA" button.  Please note that since the context variable depends on pressing a button, if the name is changed in the textinput box, the button must be pressed again to refilter the gallery. 
    _2.png

  • AdamH Profile Picture
    580 on at

    Hi @Drrickryp 

     

    Thanks for your reply!


    So if I understand this, in my example I would put ( textsearchbox1.text && mentor = “true” ) for my mentor button?

    In your example, your filter buttons are all individual buttons?

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @AdamH 

    They are all individual buttons with an UpdateContext({}) to change the variable that is used as the Items property of the gallery. Each button includes the textsearchbox and the condition as filter within the UpdateContext({ ...as you have described in your filters.  Basically, this separates each of the filters you have described in your If() condition and uses them to create a filtered table variable that is used as the Items property of the gallery depending on which button is pushed. 

     

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @AdamH 

    Glad you decided to not have a lot of screens! 😁

     

    Since your buttons are in a Gallery, you don't need any variables for what you are doing.

     

    In your Gallery Items, set the formula to the following:

    Filter(
     'NC MST Tracker',
     StartsWith('Employee Name', TextSearchBox1.Text) &&
     Switch(Gallery1.Selected.Value,
     "Mentor", <mentorYesNoColumnNameHere>,
     "AET", 'AET Instructor',
     "MST", <mstYesNoColumnNameHere>,
     true
     )
    )

    I hope this is helpful for you.

  • AdamH Profile Picture
    580 on at

    @RandyHayes @Drrickryp 

     

    Boom! You guys are the best!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 294 Most Valuable Professional

#2
11manish Profile Picture

11manish 210

#3
Valantis Profile Picture

Valantis 169

Last 30 days Overall leaderboard