cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
llacefield
Level: Powered On

Filter Gallery Based on 5 Buttons with If Statement

Hello,
Any assistance with matter would greatly be appreciated!!
I've tried many times trying to wrap my mind on the syntax of the function that I'm trying to call but have gotten nowhere. 
I have a SharePoint List that logs Jobs awarded for our company. With that SP list, I have a PowerApp that is connected to it for submitting new job numbers. The PowerApp will read the last job number submitted based on the CustomerName and then add 1, to produce a new number. 

 

If(
txt_CustomerName.Selected.Value = "Customer1",
Last(Filter(tbl_JobNumber, CustomerName.Value = txt_CustomerName.Selected.Value)).JobNumber + 1,
txt_CustomerName.Selected.Value = "Customer2",
Last(Filter(tbl_JobNumber, CustomerName.Value = txt_CustomerName.Selected.Value)).JobNumber + 1,
txt_CustomerName.Selected.Value = "Customer3",
Last(Filter(tbl_JobNumber, CustomerName.Value = txt_CustomerName.Selected.Value)).JobNumber + 1,
txt_CustomerName.Selected.Value = "CUstomer4",
Last(Filter(tbl_JobNumber, CustomerName.Value = txt_CustomerName.Selected.Value)).JobNumber + 1,
txt_CustomerName.Selected.Value = "Customer5",
Last(Filter(tbl_JobNumber, CustomerName.Value = txt_CustomerName.Selected.Value)).JobNumber + 1,
Parent.Default
)


Now I am trying to build a screen that will allow someone to filter the list with 5 buttons that represent the CustomerName. Each CustomerName button OnSelect property has a contextual variable so when the button is pressed, it will toggle true or false. 

On the Gallery Items property, I am trying to toggle between variables with an if statement saying, 

If(varCustomer1 = true, Filter(tbl_JobNumber, CustomerName.Value ="Customer1"))

 

What I'd like to happen is when button_Customer1 is pressed, the gallery will filter for that CustomerName and sort the JobNumers in descending order. I'm having the hardest time trying to write that into a nested If statement. If you need a visual of the screen, it is below.

EditScreen.jpg

 

I very well may be going about this all wrong but any help would greatly be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
RezaDorrani
Level 10

Re: Filter Gallery Based on 5 Buttons with If Statement

Hi @llacefield 

 

Just keep it simple

 

when tab1 is clicked use Set(varTabSelected,"Customer1")

when tab2 is clicked  Set(varTabSelected,"Customer2")

and so on

 

then just use the query

 

Filter(tbl_JobNumber, CustomerName.Value = varTabSelected )

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

12 REPLIES 12
RezaDorrani
Level 10

Re: Filter Gallery Based on 5 Buttons with If Statement

Hi @llacefield 

 

Better option would be to set a variable with selected tab details

when tab1 is clicked varTabSelected = "Customer1"

when tab2 is clicked  varTabSelected = "Customer2"

and so on

 

then just use the query

 

Filter(tbl_JobNumber, CustomerName.Value = varTabSelected )

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

llacefield
Level: Powered On

Re: Filter Gallery Based on 5 Buttons with If Statement

@RezaDorrani, Excellent idea! 
On the tabs (which are buttons), I'd place, 
UpdateContext({varTabSelected:
If(btn_CustomerName1.Pressed, varTabSelected = "Customer1")})

Would you say that is correct? When I do do that, I get an error on the equals sign stating, "Incompatible type: We can't evaluate your formula because the value being compared in the formula aren't the same type."

 

Super User
Super User

Re: Filter Gallery Based on 5 Buttons with If Statement

Hi @llacefield 

 

You can set the variable as:
 
Customer 1 Tab-> OnSelect -> Set(SelectedCustomer = "Customer1")
 
Customer 2 Tab-> OnSelect -> Set(SelectedCustomer = "Customer2")
 
Customer 3 Tab-> OnSelect -> Set(SelectedCustomer = "Customer3")
 
Gallery -> Items -> Filter(tbl_JobNumber, CustomerName.Value = SelectedCustomer)

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Highlighted
RezaDorrani
Level 10

Re: Filter Gallery Based on 5 Buttons with If Statement

Hi @llacefield 

 

Just keep it simple

 

when tab1 is clicked use Set(varTabSelected,"Customer1")

when tab2 is clicked  Set(varTabSelected,"Customer2")

and so on

 

then just use the query

 

Filter(tbl_JobNumber, CustomerName.Value = varTabSelected )

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

llacefield
Level: Powered On

Re: Filter Gallery Based on 5 Buttons with If Statement

That's perfect! I knew there had to be an easier way! I appreciate @RezaDorrani  and @yashag2255   for both of your responses! 
By chance, you guys know how I would go about Sorting that gallery in descending order.

 

Sort(Filter(tbl_JobNumber, CustomerName.Value = varCustomer).JobNumber,Descending) for some reason is working correctly

RezaDorrani
Level 10

Re: Filter Gallery Based on 5 Buttons with If Statement

Hi @llacefield 

 

 

SortByColumns(Filter(tbl_JobNumber, CustomerName.Value = varTabSelected ),"JobNumber",Descending)

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

llacefield
Level: Powered On

Re: Filter Gallery Based on 5 Buttons with If Statement

@RezaDorrani 
That's what I initially thought but I got this error!

 

SortByColumns-Error.jpg

 

RezaDorrani
Level 10

Re: Filter Gallery Based on 5 Buttons with If Statement

@llacefield 

 

Is JobNumber a valid column?

llacefield
Level: Powered On

Re: Filter Gallery Based on 5 Buttons with If Statement

Absolutely.

SP-LKist-Columns.png

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 78 members 4,453 guests
Please welcome our newest community members: