cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ahhollan
Post Patron
Post Patron

Use button to filter by a value range

I have built an app with records that have a data field of Days Old.  I'd like to filter the main gallery using buttons. For example, when I press a button, it should only return records with values of 0 to 5 in the Days Old field.  How do I accomplish this? I'm going to have one button for all fields, one for <5 days, one for 6-10 days, and one for >10 days.

1 ACCEPTED SOLUTION

Accepted Solutions

You had one extra parenthesis:

Filter(
'Alarm Tracking',
(variable1 && Value('Days Old')<5 && Value('Days Old')>0)
||
(variable2 && Value('Days Old')>6 && Value('Days Old')<10)
||
(variable3 && Value('Days Old')>10)
||
(!variable1 && !variable2 && !variable3)
)

Let me know if this works.

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia
https://thepoweraddict.com

View solution in original post

7 REPLIES 7
PowerAddict
Super User
Super User

For each button's OnSelect, set a variable to true. Then set the Items property of your gallery to:

Filter(Entity, If(variable1, 'Days Old' < 5 && 'Days Old' > 0, true), If(variable2, 'Days Old' > 6 && 'Days Old' < 10, true), If(variable3, 'Days Old' > 10, true)

Button1 Onselect = Set(variable1, true)
Button2 Onselect = Set(variable2, true)
Button3 Onselect = Set(variable3, true)

Let me know if this helps.

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia
https://thepoweraddict.com

The buttons aren't working. The gallery doesn't return records for any of the buttons.  My formula (i had to alter a little) is Filter('Alarm Tracking',If(variable1,Value('Days Old')<5 && Value('Days Old')>0, true),If(variable2,Value('Days Old')>6 && Value('Days Old')<10, true),If(variable3,Value('Days Old')>10, true)).

 

Also, what do I add so that the All Tickets button returns all records?

The All Tickets should simply do the following OnSelect

Set(variable1, false);
Set(variable2, false);
Set(variable3, false)

Let me do a quick check to see why it isn't working for you.

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia
https://thepoweraddict.com

I have attached a GIF that shows a simple test I did using a scenario similar to yours. Here are the important values from the test:

 

OnSelect of Variable1 Button: 

Set(variable1, true); Set(variable2, false); Set(variable3, false)

OnSelect of Variable2 Button:

Set(variable2, true); Set(variable1, false); Set(variable3, false)

OnSelect of Variable3 Button:

Set(variable3, true); Set(variable1, false); Set(variable2, false)

OnSelect of All Accounts Button:

Set(variable1, false); Set(variable2, false); Set(variable3, false)

Items property of the Gallery:

Filter(Accounts, (variable1 && 'Account Name'= "Account One") || (variable2 && 'Account Name' = "Fourth Coffee (sample)") || (variable3 && 'Account Name' = "Adventure Works (sample)") || (!variable1 && !variable2 && !variable3))

 

Based on this example, your formulas should be something like the following: 

Items property of the Gallery:

Filter('Alarm Tracking', (variable1 && Value('Days Old')<5) && Value('Days Old')>0, true) || (variable2 && Value('Days Old')>6 && Value('Days Old')<10) || (variable3 && Value('Days Old')>10) || (!variable1 && !variable2 && !variable3))

OnSelect of Variable1 Button: 

 

Set(variable1, true); Set(variable2, false); Set(variable3, false)

 

OnSelect of Variable2 Button:

 

Set(variable2, true); Set(variable1, false); Set(variable3, false)

 

OnSelect of Variable3 Button:

 

Set(variable3, true); Set(variable1, false); Set(variable2, false)

 

OnSelect of All Tickets Button:

 

Set(variable1, false); Set(variable2, false); Set(variable3, false)

 

Let me know if this helps. 

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

Thanks!
Hardit Bhatia
https://thepoweraddict.com

 

 

 

 

I'm having trouble with the Items formula. When I get to the 2nd variable and input Value, 'Days Old' is not a choice for the field but 'Days Old Datacard' is. 

 

Filter('Alarm Tracking', (variable1 && Value('Days Old')<5) && Value('Days Old')>0, true) || (variable2 && Value('Days Old')>6 && Value('Days Old')<10) || (variable3 && Value('Days Old')>10) || (!variable1 && !variable2 && !variable3))

You had one extra parenthesis:

Filter(
'Alarm Tracking',
(variable1 && Value('Days Old')<5 && Value('Days Old')>0)
||
(variable2 && Value('Days Old')>6 && Value('Days Old')<10)
||
(variable3 && Value('Days Old')>10)
||
(!variable1 && !variable2 && !variable3)
)

Let me know if this works.

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia
https://thepoweraddict.com

What if i also wanted to exclude rows where the field Condition had a status of 'Resolved'? Would that just be adding the following to the items formula for the gallery?  &&Condition<>"Resolved"

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,449)