cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Super User III
Super User III

@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 III
Super User III

@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

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

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

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