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

Add Conditions to (Multiple) Filters on Gallery

I have a gallery that filters the table time_logs based on the selected values of 2 dropdowns and 2 date pickers. Currently it runs all four filters simultaneously, so all four fields have to be complete for it to work correctly. I want to add conditions so that the filters only run if the user has selected something from the dropdown.  

 

For example-- filter_dropd_project defaults to "-" which is the first value. I would like the formula to say. If the project_name is "-", show all lines. Otherwise, filter the lines to return only the selected project. 

 

Here is the current formula: 

 

SortByColumns(Filter(time_logs, filter_dropd_project.Selected.project_name = project_id, filter_dropd_staff_person.Selected.full_name = staff_person, filter_start_date.SelectedDate >= DateValue(date), filter_end_date.SelectedDate <= DateValue(date)), "date", If(SortDescending1, Ascending, Descending))

 

1. How can I get away from this all-or-nothing issue of needing to fill out all four boxes?

 

2. What would the syntax look like of adding an If() function to my filters?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Add Conditions to (Multiple) Filters on Gallery

@justtegan 

Here's the pattern I use for multiple dropdowns.  I adapted it to your specific problem.  Notice how each filter criteria starts with ISBLANK(some_field)=true?  When no data is entered in a dropdown it ignores the filter criteria.  Otherwise, it shows only matching records.

 

SortByColumns(
    Filter(
        time_logs,
        IsBlank(filter_dropd_project.Selected.project_name)=true Or filter_dropd_project.Selected.project_name = project_id,
        IsBlank(filter_dropd_staff_person.Selected.full_name)=true Or filter_dropd_staff_person.Selected.full_name = staff_person,
        IsBlank(filter_start_date.SelectedDate)=true Or filter_start_date.SelectedDate >= DateValue(date),
        IsBlank(filter_end_date.SelectedDate)=true Or filter_end_date.SelectedDate <= DateValue(date)
    ),
    "date",
    If(SortDescending1, Ascending, Descending)
)

 

IMPORTANT!  Instead of using "-" to indicate no selection use "" instead.  If you want to use a PowerApps function create the "" you can use Blank()

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

2 REPLIES 2
Super User
Super User

Re: Add Conditions to (Multiple) Filters on Gallery

@justtegan 

Here's the pattern I use for multiple dropdowns.  I adapted it to your specific problem.  Notice how each filter criteria starts with ISBLANK(some_field)=true?  When no data is entered in a dropdown it ignores the filter criteria.  Otherwise, it shows only matching records.

 

SortByColumns(
    Filter(
        time_logs,
        IsBlank(filter_dropd_project.Selected.project_name)=true Or filter_dropd_project.Selected.project_name = project_id,
        IsBlank(filter_dropd_staff_person.Selected.full_name)=true Or filter_dropd_staff_person.Selected.full_name = staff_person,
        IsBlank(filter_start_date.SelectedDate)=true Or filter_start_date.SelectedDate >= DateValue(date),
        IsBlank(filter_end_date.SelectedDate)=true Or filter_end_date.SelectedDate <= DateValue(date)
    ),
    "date",
    If(SortDescending1, Ascending, Descending)
)

 

IMPORTANT!  Instead of using "-" to indicate no selection use "" instead.  If you want to use a PowerApps function create the "" you can use Blank()

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

justtegan
Level: Powered On

Re: Add Conditions to (Multiple) Filters on Gallery

Perfection. Thank you so much for your help. I suspected that "-" would be an issue.

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,100)