cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sababneh
Advocate IV
Advocate IV

Multiple Filter for Gallery using Combobox

Hey all,

 

I know there are a lot of topics explaining this one. But I could't find what I'm looking for, because I want:

  • 4 Comboboxes to filter the gallery
  • I want the gallery to show results even if none of the comboxes are selected or even one is selected

What I'm having that I have to select all four Comboboxes to get results.

 

What I want:

  • The gallery to show results even if one of the comboboxes is selected or even none

That code i'm using:

If(IsBlank(ComboBox1.Selected.Result) && IsBlank(ComboBox2.Selected.Result) && IsBlank(ComboBox3.Selected.Result) && IsBlank(ComboBox4.Selected.Result),SortByColumns(TasksData,"Title",Descending),SortByColumns(Filter(TasksData,StartsWith(TaskTarget,ComboBox1.Selected.Result),StartsWith(TaskCenter,ComboBox2.Selected.Result),StartsWith(Employee,ComboBox3.Selected.Result),StartsWith(TaskSubject,ComboBox4.Selected.Result)),"Title",Descending))

1 ACCEPTED SOLUTION

Accepted Solutions
Sienna
Resident Rockstar
Resident Rockstar

Here is sample of filtering datasource with 4 comboboxes. I only covered 8 switches so you will have to finish it co cover all scenario

 

Switch(true, IsBlank(ComboBox1.Selected.Text1) && IsBlank(ComboBox2.Selected.Text1) && IsBlank(ComboBox3.Selected.Text1) && IsBlank(ComboBox4.Selected.Text1),   
                TestColection,
Not(IsBlank(ComboBox1.Selected.Text1)) && IsBlank(ComboBox2.Selected.Text1) && IsBlank(ComboBox3.Selected.Text1) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox1.Selected.Text1), Not(IsBlank(ComboBox1.Selected.Text1)) && Not(IsBlank(ComboBox2.Selected.Text1)) && IsBlank(ComboBox3.Selected.Text1) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox1.Selected.Text1 && Col2=ComboBox2.Selected.Text1), Not(IsBlank(ComboBox1.Selected.Text1)) && Not(IsBlank(ComboBox2.Selected.Text1)) && Not(IsBlank(ComboBox3.Selected.Text1)) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox1.Selected.Text1 && Col2=ComboBox2.Selected.Text1 && Col3=ComboBox3.Selected.Text1), Not(IsBlank(ComboBox1.Selected.Text1)) && Not(IsBlank(ComboBox2.Selected.Text1)) && Not(IsBlank(ComboBox3.Selected.Text1)) && Not(IsBlank(ComboBox4.Selected.Text1)), Filter(TestColection,Col1=ComboBox1.Selected.Text1 && Col2=ComboBox2.Selected.Text1 && Col3=ComboBox3.Selected.Text1 && Col3=ComboBox4.Selected.Text1), IsBlank(ComboBox1.Selected.Text1) && Not(IsBlank(ComboBox2.Selected.Text1)) && IsBlank(ComboBox3.Selected.Text1) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox2.Selected.Text1), IsBlank(ComboBox1.Selected.Text1) && Not(IsBlank(ComboBox2.Selected.Text1)) && Not(IsBlank(ComboBox3.Selected.Text1)) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox2.Selected.Text1 && Col2=ComboBox3.Selected.Text1), IsBlank(ComboBox1.Selected.Text1) && Not(IsBlank(ComboBox2.Selected.Text1)) && Not(IsBlank(ComboBox3.Selected.Text1)) && Not(IsBlank(ComboBox4.Selected.Text1)), Filter(TestColection,Col1=ComboBox2.Selected.Text1 && Col2=ComboBox3.Selected.Text1 && Col3=ComboBox4.Selected.Text1)
.
.
.)

View solution in original post

6 REPLIES 6
Sienna
Resident Rockstar
Resident Rockstar

You will have to define how you want to filter your database for each scenario. I would use SWITCH function for it. With 4 cmboboxes you should end up with 16 switches or even more to define each scenario if I’m not mistaken. Good luck

Can you provide me with a quick example on how I'm gonna do it?

Sienna
Resident Rockstar
Resident Rockstar

I’m not at my PC right now but you can find documentation for the switch here

https://docs.microsoft.com/en-us/powerapps/functions/function-if
Sienna
Resident Rockstar
Resident Rockstar

Here is sample of filtering datasource with 4 comboboxes. I only covered 8 switches so you will have to finish it co cover all scenario

 

Switch(true, IsBlank(ComboBox1.Selected.Text1) && IsBlank(ComboBox2.Selected.Text1) && IsBlank(ComboBox3.Selected.Text1) && IsBlank(ComboBox4.Selected.Text1),   
                TestColection,
Not(IsBlank(ComboBox1.Selected.Text1)) && IsBlank(ComboBox2.Selected.Text1) && IsBlank(ComboBox3.Selected.Text1) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox1.Selected.Text1), Not(IsBlank(ComboBox1.Selected.Text1)) && Not(IsBlank(ComboBox2.Selected.Text1)) && IsBlank(ComboBox3.Selected.Text1) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox1.Selected.Text1 && Col2=ComboBox2.Selected.Text1), Not(IsBlank(ComboBox1.Selected.Text1)) && Not(IsBlank(ComboBox2.Selected.Text1)) && Not(IsBlank(ComboBox3.Selected.Text1)) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox1.Selected.Text1 && Col2=ComboBox2.Selected.Text1 && Col3=ComboBox3.Selected.Text1), Not(IsBlank(ComboBox1.Selected.Text1)) && Not(IsBlank(ComboBox2.Selected.Text1)) && Not(IsBlank(ComboBox3.Selected.Text1)) && Not(IsBlank(ComboBox4.Selected.Text1)), Filter(TestColection,Col1=ComboBox1.Selected.Text1 && Col2=ComboBox2.Selected.Text1 && Col3=ComboBox3.Selected.Text1 && Col3=ComboBox4.Selected.Text1), IsBlank(ComboBox1.Selected.Text1) && Not(IsBlank(ComboBox2.Selected.Text1)) && IsBlank(ComboBox3.Selected.Text1) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox2.Selected.Text1), IsBlank(ComboBox1.Selected.Text1) && Not(IsBlank(ComboBox2.Selected.Text1)) && Not(IsBlank(ComboBox3.Selected.Text1)) && IsBlank(ComboBox4.Selected.Text1), Filter(TestColection,Col1=ComboBox2.Selected.Text1 && Col2=ComboBox3.Selected.Text1), IsBlank(ComboBox1.Selected.Text1) && Not(IsBlank(ComboBox2.Selected.Text1)) && Not(IsBlank(ComboBox3.Selected.Text1)) && Not(IsBlank(ComboBox4.Selected.Text1)), Filter(TestColection,Col1=ComboBox2.Selected.Text1 && Col2=ComboBox3.Selected.Text1 && Col3=ComboBox4.Selected.Text1)
.
.
.)

Wow Sienna, you are wonderful thanks.

I did something like this yesterday:

 

If(IsBlank(first.Text)&&IsBlank(second.Text)&&IsBlank(third.Text)&&IsBlank(fourth.Text),SortByColumns(TasksData,"Title",Descending),If(Not(IsBlank(first.Text))&&Not(IsBlank(second.Text))&&Not(IsBlank(third.Text))&&Not(IsBlank(fourth.Text)),SortByColumns(Filter(TasksData,TaskTarget=first.Text,TaskCenter=second.Text,Employee=third.Text,TaskSubject=fourth.Text),"Title",Descending),If(Not(IsBlank(first.Text))&&Not(IsBlank(second.Text))&&IsBlank(third.Text)&&Not(IsBlank(fourth.Text)),SortByColumns(Filter(TasksData,TaskTarget=first.Text,TaskCenter=second.Text,TaskSubject=fourth.Text),"Title",Descending),If(Not(IsBlank(first.Text))&&IsBlank(second.Text)&&Not(IsBlank(third.Text))&&Not(IsBlank(fourth.Text)),SortByColumns(Filter(TasksData,TaskTarget=first.Text,Employee=third.Text,TaskSubject=fourth.Text),"Title",Descending),If(Not(IsBlank(first.Text))&&Not(IsBlank(second.Text))&&Not(IsBlank(third.Text))&&IsBlank(fourth.Text),SortByColumns(Filter(TasksData,TaskTarget=first.Text,TaskCenter=second.Text,Employee=third.Text),"Title",Descending),If(IsBlank(first.Text)&&Not(IsBlank(second.Text))&&Not(IsBlank(third.Text))&&Not(IsBlank(fourth.Text)),SortByColumns(Filter(TasksData,TaskCenter=second.Text,Employee=third.Text,TaskSubject=fourth.Text),"Title",Descending),If(Not(IsBlank(first.Text))&&IsBlank(second.Text)&&IsBlank(third.Text)&&Not(IsBlank(fourth.Text)),SortByColumns(Filter(TasksData,TaskTarget=first.Text,TaskSubject=fourth.Text),"Title",Descending),If(Not(IsBlank(first.Text))&&IsBlank(second.Text)&&Not(IsBlank(third.Text))&&IsBlank(fourth.Text),SortByColumns(Filter(TasksData,TaskTarget=first.Text,Employee=third.Text),"Title",Descending),If(Not(IsBlank(first.Text))&&Not(IsBlank(second.Text))&&IsBlank(third.Text)&&IsBlank(fourth.Text),SortByColumns(Filter(TasksData,TaskTarget=first.Text,TaskCenter=second.Text),"Title",Descending),If(IsBlank(first.Text)&&Not(IsBlank(second.Text))&&IsBlank(third.Text)&&Not(IsBlank(fourth.Text)),SortByColumns(Filter(TasksData,TaskCenter=second.Text,TaskSubject=fourth.Text),"Title",Descending),If(IsBlank(first.Text)&&Not(IsBlank(second.Text))&&Not(IsBlank(third.Text))&&IsBlank(fourth.Text),SortByColumns(Filter(TasksData,TaskCenter=second.Text,Employee=third.Text),"Title",Descending),If(IsBlank(first.Text)&&IsBlank(second.Text)&&Not(IsBlank(third.Text))&&Not(IsBlank(fourth.Text)),SortByColumns(Filter(TasksData,Employee=third.Text,TaskSubject=fourth.Text),"Title",Descending),If(Not(IsBlank(first.Text))&&IsBlank(second.Text)&&IsBlank(third.Text)&&IsBlank(fourth.Text),SortByColumns(Filter(TasksData,TaskTarget=first.Text),"Title",Descending),If(IsBlank(first.Text)&&Not(IsBlank(second.Text))&&IsBlank(third.Text)&&IsBlank(fourth.Text),SortByColumns(Filter(TasksData,TaskCenter=second.Text),"Title",Descending),If(IsBlank(first.Text)&&IsBlank(second.Text)&&Not(IsBlank(third.Text))&&IsBlank(fourth.Text),SortByColumns(Filter(TasksData,Employee=third.Text),"Title",Descending),If(IsBlank(first.Text)&&IsBlank(second.Text)&&IsBlank(third.Text)&&Not(IsBlank(fourth.Text)),SortByColumns(Filter(TasksData,TaskSubject=fourth.Text),"Title",Descending)))))))))))))))))

I didn't use the Switch because I didn't understand it.

 

Is it better to use the Switch you provided or I can do it with an If like I did?

 

Thank you again

You can use "if" if you like. I prefer to use switch because the code is less messy

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,154)