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 / Help with Filtering by...
Power Apps
Unanswered

Help with Filtering by Buttons

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hey everyone!

 

I am having issues with filtering by buttons. I have three buttons representing statuses: red, yellow, and green. In my sharepoint list I have a calculated column named HealthStatus that feeds out a number 0(green), 1(yellow), or 2(red) based on certain specifications. I am trying to have these buttons, when selected, only show gallery items where the calcuated column equals the corresponding number.

 

I found this forum post where the user had a very similar issue so I tried to follow the solution. I set my buttons to 

Set(redStatus,2)

and when I tried to edit my gallery items formula, no matter what I put in, I get errors and it breaks my gallery. Here is my current gallery code

SortByColumns(
 Filter(
 [@'DCHealth'],
 StartsWith(
 DC,
 TextSearchBox1.Text
 ) && (Region in RegionCombo.SelectedItems.Value || RegionCombo.Selected.Value = Blank())
 ),
 "field_3",
 If(
 SortDescending1,
 SortOrder.Ascending,
 SortOrder.Descending
 )
)

I tried placing If(redStatus=2,'DCHealth', Filter('DCHealth',HealthStatus=redStatus)) after my region filter but I get a multitude of errors.

 

How should I edit this or change my course of action to get these filter buttons running? 

 

Thanks!

Categories:
  • madlad Profile Picture
    2,637 Moderator on at

    Try changing to something like:

    SortByColumns(
     If(
     redStatus = 2,
     Filter(
     'DCHealth',
     StartsWith(DC, TextSearchBox1.Text) && 
     (Region in RegionCombo.SelectedItems.Value || RegionCombo.Selected.Value = Blank())
     ),
     Filter(
     'DCHealth',
     HealthStatus = redStatus &&
     StartsWith(DC, TextSearchBox1.Text) && 
     (Region in RegionCombo.SelectedItems.Value || RegionCombo.Selected.Value = Blank())
     )
     ),
     "field_3",
     If(
     SortDescending1,
     SortOrder.Ascending,
     SortOrder.Descending
     )
    )

    Please note I haven't tested so it may require a bit of playing with.

     

    Hope this helps!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you! This doesn't break my gallery, which is such a relief.

     

     But, the buttons are not operating. When selected, the gallery does not change at all. Is there something that I am missing in order to have them work?

  • madlad Profile Picture
    2,637 Moderator on at

    You're certain that all of the variables are being changed correctly? You could temporarily put a label and set the value to redStatus just to confirm that the variable is changing with each button press.

     

    If that's ok, one thing you could try is to put "Reset(YourGallery)" in the button's OnSelect after the variable is assigned, but I don't necessarily see why you would need that here.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hey @madlad ,

     

    I added labels to see if my variables have the correct values and they do. They do not change upon button click though and instead stay the correct value regardless.

     

    I put in the Reset(YourGallery) and it didn't seem to make a difference. 

  • madlad Profile Picture
    2,637 Moderator on at

    You mean that redStatus is always 2? What's the code in each of your buttons?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    each follow this formula: Set(redStatus, 2).

     

    I fiddled around a little bit, if I change the value in one of then, my live preview of the gallery disappears as well as the text label holding the variable. When I go into the play mode and then select the button, everything reappears (not sorted) and the label appears with the correct value in it. This makes me think there is something wrong with the actual filtering in the gallery. 

     

    Thank you for helping me solve this issue!

  • madlad Profile Picture
    2,637 Moderator on at

    Just to confirm, you mean that when the green button is selected,

    Set(redStatus, 0);

    , when the Yellow one is selected

    Set(redStatus, 1);

    and when red is selected 

    Set(redStatus, 2);

    If this is the case, it could be something in the filter statement - what's the code for the filter statements, did you copy it directly from my answer, or modify it a bit? 

     

    The reason everything was disappearing when you edited it was because variables will reset and become blank when their code is edited like this.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Green/yellow are 

    Set(yellowStatus, 1);
    Set(greenStatus, 0);

    and this is the code for the filter statements in my Gallery->items panel. I haven't tried putting in the other buttons yet, but when red works I will add yellowStatus and greenStatus to this filter

    SortByColumns(
     If(
     redStatus = 2,
     Filter(
     'DCHealth',
     StartsWith(DC, TextSearchBox1.Text) && 
     (Region in RegionCombo.SelectedItems.Value || RegionCombo.Selected.Value = Blank())
     ),
     Filter(
     'DCHealth',
     HealthStatus = redStatus &&
     StartsWith(DC, TextSearchBox1.Text) && 
     (Region in RegionCombo.SelectedItems.Value || RegionCombo.Selected.Value = Blank())
     )
     ),
     "field_3",
     If(
     SortDescending1,
     SortOrder.Ascending,
     SortOrder.Descending
     )
     
    )
  • madlad Profile Picture
    2,637 Moderator on at

    Ah i see now.

     

    If you don't have any code to reset redStatus elsewhere, it will never change once it's set as 2.

     

    If you want to be able to press the red button a second time to change the filter back, you could have your red button's onselect look something like:

    If(redStatus = 2,
     Set(redStatus, -1),
     Set(redStatus, 2)
    )

     as this will alternate the values of it. 

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard