cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ClaireAllen
Post Prodigy
Post Prodigy

Filter Gallery using Multiple Buttons

Hello Community,
I need your help please!
I'm building an App that has multiple buttons where I want to filter the gallery

These are my buttons choices

ClaireAllen_0-1622723239488.png

I have managed to get the Approved button working by adding this formula UpdateContext({FilterByApproved:!FilterByApproved}) in the OnSelect Properties, 

and in the gallery items properties I have this formula, Filter(LithuaniaLeaveRequest, 'Created By'.Email = User().Email, If(FilterByApproved = true, Status.Value = "Approved", Status.Value<>""))

When I try the same principle for the other buttons I don't seem to get the same result.
I would like to only show the items in the gallery if the following is true

Status Value = 
Approved
Declined

Or contains Pending HR Approval Or contains Pending Manager Approval

 

Can anyone help me with a solution please.
Thank you in advance

Claire

1 ACCEPTED SOLUTION

Accepted Solutions
CNT
Super User
Super User

@ClaireAllen Try this,

We'll use just one variable.

In the OnSelect of All: UpdateContext({varFilterBy:""})

In the OnSelect of Pending: UpdateContext({varFilterBy:"Pending"})

In the OnSelect of Approved: UpdateContext({varFilterBy:"Approved"})

In the OnSelect of Declined: UpdateContext({varFilterBy:"Declined"})

 

In the Items of the gallery put this code,

Filter(LithuaniaLeaveRequest, 'Created By'.Email = User().Email &&
Switch(varFilterBy,
   "Pending", Status.Value = "Pending",
   "Approved", Status.Value = "Approved",
   "Declined", Status.Value = "Declined",
   true)
)

 

Please remember to give a 👍 and accept the solution as it will help others in the future.

 

 

View solution in original post

6 REPLIES 6
BCLS776
Super User
Super User

Are your four buttons mutually exclusive selections? If so, how about putting an If statement on the Items property:

 

If(FilterByApproved, // insert code to Filter by Approved status
    ,
    FilterByDeclined, // insert code to Filter by Declined status
    ,
    SearchByPending, // insert code to Search for Pending status
    ,
    LithuaniaLeaveRequest // to show all as the default
)

 



_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.
zmansuri
Super User
Super User

instead of going through all this trouble. Create one SharePoint choice Colum named "State" give choice like

Pending,Approved,Decline

Instead of buttons. Provide a dropdown with those values. and you will be able to filter your gallery without any variable like

 Filter(LithuaniaLeaveRequest,

'Created By'.Email = User().Email,

State.Value=Dropdown.Selected.Value || Dropdown.Selected.Value="All")

CNT
Super User
Super User

@ClaireAllen Try this,

We'll use just one variable.

In the OnSelect of All: UpdateContext({varFilterBy:""})

In the OnSelect of Pending: UpdateContext({varFilterBy:"Pending"})

In the OnSelect of Approved: UpdateContext({varFilterBy:"Approved"})

In the OnSelect of Declined: UpdateContext({varFilterBy:"Declined"})

 

In the Items of the gallery put this code,

Filter(LithuaniaLeaveRequest, 'Created By'.Email = User().Email &&
Switch(varFilterBy,
   "Pending", Status.Value = "Pending",
   "Approved", Status.Value = "Approved",
   "Declined", Status.Value = "Declined",
   true)
)

 

Please remember to give a 👍 and accept the solution as it will help others in the future.

 

 

Hello @zmansuri 
Thank you for taking the time to come back to me
My Column is already a choice column, and I wanted to use buttons but looking at your option I see that this would also work.
Thank you
Claire

Hello @CNT 
Thank you for taking the time to come back to me
I think this is what I was trying to achieve, with the UpdateContext, I just could not get it to work but now I can.
Kind regards

Claire

@ClaireAllen Glad to help! 

Helpful resources

Announcements
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.

PWREduCon768x460.png

Join us at PWR EduCon - A Power Platform Conference

Learn from the top Power BI, Power Apps, Power Automate & Power Virtual Agents experts!

Top Solution Authors
Top Kudoed Authors
Users online (2,388)