cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
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
Highlighted
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

Highlighted
Frequent Visitor

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
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,512)