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

Filter a gallery by a radio button

i'm using the case management template with some modifications to link to a sharepoint list

2017-10-06_16-12-34.png

 

the "items" field for GalleryCases is nearly the same as its default (i only changed the data source and some column names):

 

If(IsEmpty
	(CustomFilter) || First(CustomFilter).value = "All",
		Sort(
			Filter(Cases,searchBar.Text in Title),Created,Descending
		), 
			First(CustomFilter).type = "Status", 
		Sort(
			Filter(Cases,searchBar.Text in Title && OData__Status.Value in First(CustomFilter).value),Created,Descending
		), 
			First(CustomFilter).type = "Priority", 
		Sort(
			Filter(Cases,searchBar.Text in Title && Priority.Value in 
			First(CustomFilter).value
		),Created,Descending
        )
)

i want to also filter GalleryCases with the two radio button lists i've added, ProductRadio and CategoryRadio. they're linked to my sharepoint columns Product.Value and Category.Value. i cannot for the life of me figure out how to add that into GalleryCases Items without ruining the whole gallery. can someone help?

1 ACCEPTED SOLUTION

Accepted Solutions
JRaasumaa
Level 10

Re: Filter a gallery by a radio button


@cyarbrough wrote:

thanks for the response. i set up both radio buttons with that formula and alone they both work great, but i don't know how to get all three sets of filters to work on the same gallery. 

 

If(IsEmpty(CustomFilter) || First(CustomFilter).value = "All",Sort(Filter(Cases,searchBar.Text in Title),Created,Descending), 
First(CustomFilter).type = "Status", Sort(Filter(Cases,searchBar.Text in Title && OData__Status.Value in First(CustomFilter).value),Created,Descending), 
First(CustomFilter).type = "Priority", Sort(Filter(Cases,searchBar.Text in Title && Priority.Value in First(CustomFilter).value),Created,Descending))
If(ProductRadio.Selected.Value="S5000 Safe",Filter(Cases,Product.Value in "S5000 Safe"),
ProductRadio.Selected.Value="S6000 Safe",Filter(Cases,Product.Value in "S6000 Safe"),
ProductRadio.Selected.Value="P5100",Filter(Cases,Product.Value in "P5100"),
ProductRadio.Selected.Value="P2000",Filter(Cases,Product.Value in "P2000"), Cases)
If(CategoryRadio.Selected.Value="Hardware",Filter(Cases,Category.Value in "Hardware"),
CategoryRadio.Selected.Value="Software",Filter(Cases,Category.Value in "Software"),
CategoryRadio.Selected.Value="Other",Filter(Cases,Category.Value in "Other"), Cases)

when i try to put them all into Gallery.Items together, this happens:

image.png

 

what am i doing wrong? how do i link the 3? i've tried commas, &&s , and semicolons and i get the same problem with all of them.


 

I think the solution to your answer lies in the Switch statement.

 

You need to combine your two radio boxes into a filter with && but it's difficult to do with If statements as you need a lot of nested conditions for every radio box posibility.

 

The Switch statement allows you to compare the Radio button against a list of values and run a Filter against it.

 

For example:

 

From my original solution above I've now added a Year radio button called Radio2. 

 

Now in the gallery instead of using an IF against just the 1 radio button, I have a switch to filter against both.

 

Filter(QuoteNumberMerged,QNum=Switch(Radio1.Selected.Value,"3001","3001","3002","3002",QNum) && Year=Switch(Radio1_1.Selected.Value,"2016","2016","2017","2017",Year))

Check out how Switch works here: https://powerapps.microsoft.com/en-us/tutorials/function-if/

 

This allows the filter to look at both Radio buttons for their current selection and filter based on each.

 

In your case you will want to add this switch statement filter for both your ProductRadio and CategoryRadio to the gallery filter and combine it with your original searchBar.Text and CustomFilter.Value filter. This is difficult to do without having your actual App to run against but the switch for the radio buttons may look something like:

 

 

Product in Switch(ProductRadio.Selected.Value, "S5000 Safe", "S5000 Safe", "S6000 Safe", "S6000 Safe", "P5100", "P5100", "P2000", "P2000", Product) 

 

 

with the second looking like:

 

 

Category in Switch(CategoryRadio.Selected.Value, "Hardware", "Hardware", "Software", "Software", "Other", "Other", Category)

 

 

Then it's just a matter of adding this to each filter:

 

Sort(Filter(Cases,searchBar.Text in Title
&&
Product in Switch(ProductRadio.Selected.Value, "S5000 Safe", "S5000 Safe", "S6000 Safe", "S6000 Safe", "P5100", "P5100", "P2000", "P2000", Product)
&&
Category in Switch(CategoryRadio.Selected.Value, "Hardware", "Hardware", "Software", "Software", "Other", "Other", Category)
),Created,Descending)

 

 Again without having your App it's a bit tough to figure out exactly but this should get you started with combining your filters.

 

 

 

9 REPLIES 9
Super User
Super User

Re: Filter a gallery by a radio button

Hi @cyarbrough

 

A quick guie.

Like any other behavior formula, a radio button has an action

- toggle true (Select)

- toggle false

 

Always use:

- ClearCollect(CollectionName, Filter(....as of your original formula)), to collect into CollectionName

- Then, the Gallery.Items = CollectionName

 

So it means, as long as Gallery.Items = CollectionName,

Any behavior formula can use ClearCollect to create a temporarory CollectioName (all with same CollectionName), so it will pass the filtered resultsinto the Gallery,Items.

I hope this helps.

 

THis is something NOT described in Tutorials but very important.

Have a ncie day.

hpkeong
cyarbrough
Level: Powered On

Re: Filter a gallery by a radio button

thanks for the response. sorry, i'm still having trouble with this. i have this in OnSelect for each radio button:

ClearCollect(Product, ProductRadio.Selected)
ClearCollect(Category, CategoryRadio.Selected)

i'm still not sure how to add filtering based on the radio buttons/their collections to the main gallery. i need to add it to the code that's already there (included in the OP). everything i've tried breaks the whole gallery.

cyarbrough
Level: Powered On

Re: Filter a gallery by a radio button

still really need help with this

JRaasumaa
Level 10

Re: Filter a gallery by a radio button


@cyarbrough wrote:

thanks for the response. sorry, i'm still having trouble with this. i have this in OnSelect for each radio button:

ClearCollect(Product, ProductRadio.Selected)
ClearCollect(Category, CategoryRadio.Selected)

i'm still not sure how to add filtering based on the radio buttons/their collections to the main gallery. i need to add it to the code that's already there (included in the OP). everything i've tried breaks the whole gallery.


 

Why don't you just add a conditional statement to your gallery similar to your current filters that says if a radio box = a value then apply a filter to the collection using a specific field?

 

For example:

 

I have 3 Radio buttons in a list Radio1, "All" "3001" and "3002"

 

In the Gallery I have the Items property set to:

 

If(Radio1.Selected.Value="3001",Filter(QuoteNumberMerged,QNum="3001"),Radio1.Selected.Value="3002",Filter(QuoteNumberMerged,QNum="3002"),QuoteNumberMerged)

It's clunky with lots of values but the overall function works fantastic. 

cyarbrough
Level: Powered On

Re: Filter a gallery by a radio button

thanks for the response. i set up both radio buttons with that formula and alone they both work great, but i don't know how to get all three sets of filters to work on the same gallery. 

 

If(IsEmpty(CustomFilter) || First(CustomFilter).value = "All",Sort(Filter(Cases,searchBar.Text in Title),Created,Descending), 
First(CustomFilter).type = "Status", Sort(Filter(Cases,searchBar.Text in Title && OData__Status.Value in First(CustomFilter).value),Created,Descending), 
First(CustomFilter).type = "Priority", Sort(Filter(Cases,searchBar.Text in Title && Priority.Value in First(CustomFilter).value),Created,Descending))
If(ProductRadio.Selected.Value="S5000 Safe",Filter(Cases,Product.Value in "S5000 Safe"),
ProductRadio.Selected.Value="S6000 Safe",Filter(Cases,Product.Value in "S6000 Safe"),
ProductRadio.Selected.Value="P5100",Filter(Cases,Product.Value in "P5100"),
ProductRadio.Selected.Value="P2000",Filter(Cases,Product.Value in "P2000"), Cases)
If(CategoryRadio.Selected.Value="Hardware",Filter(Cases,Category.Value in "Hardware"),
CategoryRadio.Selected.Value="Software",Filter(Cases,Category.Value in "Software"),
CategoryRadio.Selected.Value="Other",Filter(Cases,Category.Value in "Other"), Cases)

when i try to put them all into Gallery.Items together, this happens:

image.png

 

what am i doing wrong? how do i link the 3? i've tried commas, &&s , and semicolons and i get the same problem with all of them.

JRaasumaa
Level 10

Re: Filter a gallery by a radio button


@cyarbrough wrote:

thanks for the response. i set up both radio buttons with that formula and alone they both work great, but i don't know how to get all three sets of filters to work on the same gallery. 

 

If(IsEmpty(CustomFilter) || First(CustomFilter).value = "All",Sort(Filter(Cases,searchBar.Text in Title),Created,Descending), 
First(CustomFilter).type = "Status", Sort(Filter(Cases,searchBar.Text in Title && OData__Status.Value in First(CustomFilter).value),Created,Descending), 
First(CustomFilter).type = "Priority", Sort(Filter(Cases,searchBar.Text in Title && Priority.Value in First(CustomFilter).value),Created,Descending))
If(ProductRadio.Selected.Value="S5000 Safe",Filter(Cases,Product.Value in "S5000 Safe"),
ProductRadio.Selected.Value="S6000 Safe",Filter(Cases,Product.Value in "S6000 Safe"),
ProductRadio.Selected.Value="P5100",Filter(Cases,Product.Value in "P5100"),
ProductRadio.Selected.Value="P2000",Filter(Cases,Product.Value in "P2000"), Cases)
If(CategoryRadio.Selected.Value="Hardware",Filter(Cases,Category.Value in "Hardware"),
CategoryRadio.Selected.Value="Software",Filter(Cases,Category.Value in "Software"),
CategoryRadio.Selected.Value="Other",Filter(Cases,Category.Value in "Other"), Cases)

when i try to put them all into Gallery.Items together, this happens:

image.png

 

what am i doing wrong? how do i link the 3? i've tried commas, &&s , and semicolons and i get the same problem with all of them.


 

I think the solution to your answer lies in the Switch statement.

 

You need to combine your two radio boxes into a filter with && but it's difficult to do with If statements as you need a lot of nested conditions for every radio box posibility.

 

The Switch statement allows you to compare the Radio button against a list of values and run a Filter against it.

 

For example:

 

From my original solution above I've now added a Year radio button called Radio2. 

 

Now in the gallery instead of using an IF against just the 1 radio button, I have a switch to filter against both.

 

Filter(QuoteNumberMerged,QNum=Switch(Radio1.Selected.Value,"3001","3001","3002","3002",QNum) && Year=Switch(Radio1_1.Selected.Value,"2016","2016","2017","2017",Year))

Check out how Switch works here: https://powerapps.microsoft.com/en-us/tutorials/function-if/

 

This allows the filter to look at both Radio buttons for their current selection and filter based on each.

 

In your case you will want to add this switch statement filter for both your ProductRadio and CategoryRadio to the gallery filter and combine it with your original searchBar.Text and CustomFilter.Value filter. This is difficult to do without having your actual App to run against but the switch for the radio buttons may look something like:

 

 

Product in Switch(ProductRadio.Selected.Value, "S5000 Safe", "S5000 Safe", "S6000 Safe", "S6000 Safe", "P5100", "P5100", "P2000", "P2000", Product) 

 

 

with the second looking like:

 

 

Category in Switch(CategoryRadio.Selected.Value, "Hardware", "Hardware", "Software", "Software", "Other", "Other", Category)

 

 

Then it's just a matter of adding this to each filter:

 

Sort(Filter(Cases,searchBar.Text in Title
&&
Product in Switch(ProductRadio.Selected.Value, "S5000 Safe", "S5000 Safe", "S6000 Safe", "S6000 Safe", "P5100", "P5100", "P2000", "P2000", Product)
&&
Category in Switch(CategoryRadio.Selected.Value, "Hardware", "Hardware", "Software", "Software", "Other", "Other", Category)
),Created,Descending)

 

 Again without having your App it's a bit tough to figure out exactly but this should get you started with combining your filters.

 

 

 

Highlighted
cyarbrough
Level: Powered On

Re: Filter a gallery by a radio button

this works great! thank you so much.

JRaasumaa
Level 10

Re: Filter a gallery by a radio button


@cyarbrough wrote:

this works great! thank you so much.


 

You are welcome! Glad to help guide you to the right solution.

cyarbrough
Level: Powered On

Re: Filter a gallery by a radio button

alright i'm back at it again with another question

 

 

image.png

 

 

the filtering from before was working with no problems, but now i need these two extra radio button options to filter the cases gallery too ("all safes" and "all readers."). i've set up the buttons and 2 working collections of all the cases whose product.value = a safe and all cases whose product.value = a reader. now all i need is for these new radio buttons to work in the filtering formula for the cases gallery:

 

If(IsEmpty(CustomFilter) || First(CustomFilter).value = "All",Sort(Filter(Cases,searchBar.Text in Title
&&
Product.Value in Switch(ProductRadio.Selected.Value, "S5000 Safe", "S5000 Safe", "S6000 Safe", "S6000 Safe", "P5100", "P5100", "P2000", "P2000", "P6000", "P6000", Product.Value)
&&
Category.Value in Switch(CategoryRadio.Selected.Value, "Hardware", "Hardware", "Software", "Software", "Other", "Other", Category.Value)
),Created,Descending), 
First(CustomFilter).type = "Status", Sort(Filter(Cases,searchBar.Text in Title && OData__Status.Value in First(CustomFilter).value &&
Product.Value in Switch(ProductRadio.Selected.Value, "S5000 Safe", "S5000 Safe", "S6000 Safe", "S6000 Safe", "P5100", "P5100", "P2000", "P2000","P6000", "P6000", Product.Value)
&&
Category.Value in Switch(CategoryRadio.Selected.Value, "Hardware", "Hardware", "Software", "Software", "Other", "Other", Category.Value)
),Created,Descending), 
First(CustomFilter).type = "Priority", Sort(Filter(Cases,searchBar.Text in Title && Priority.Value in First(CustomFilter).value &&
Product.Value in Switch(ProductRadio.Selected.Value, "S5000 Safe", "S5000 Safe", "S6000 Safe", "S6000 Safe", "P5100", "P5100", "P2000", "P2000","P6000", "P6000", Product.Value)
&&
Category.Value in Switch(CategoryRadio.Selected.Value, "Hardware", "Hardware", "Software", "Software", "Other", "Other", Category.Value)
),Created,Descending))

can anyone help out?

 

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

Top Kudoed Authors
Users Online
Currently online: 117 members 3,913 guests
Please welcome our newest community members: