cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RussellGove
Kudo Kingpin
Kudo Kingpin

Filtering on multiple fields

Hi ,

I have a gallery and i'm trying to give users several ways to filter it. I have controls above the gallery to let the user select a Year, region, customer or keyword to filter on. I want to use only the filters the user has selected. 

 

My script ends up looking like this (this represents just the conditions, not the actual filters):

conditions.PNG

 

After adding the actual filtering logic for each condition (and god forbid an other condition) this ends up being hundreds of lines of script that are largely incomprehensible, even to the author!

 

Is there a better way to do this?

 

What we really need is a real code editor! If i could edit this script in an intelligent VSCode editor I'd have this done in minutes. The way it is it's taking days!

 

Please give me back my curly braces!

3 ACCEPTED SOLUTIONS

Accepted Solutions
mdevaney
Super User
Super User

@RussellGove 

Here's my pattern for filtering on multiple fields.  Put this code in the Items property of your gallery.

 

Filter(
    FPARequests,
    If(
        IsBlank(tbYear.Text),
        true,
        Year = tbYear.Text
    ),
    If(
        IsEmpty(cbxRegion.Selected),
        true,
        Region = cbxRegion.Selected
    ),
    If(
        IsBlank(tbCustomer.Text),
        true,
        Customer = tbCustomer.Text
    ),
    If(
        IsBlank(tbKeyword.Text),
        true,
        Keyword = tbKeyword.Text
    )
)

 

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

@RussellGove
Glad to hear it’s working now. Please mark the post that solved your issue as the solution so others can find it in the future.

View solution in original post

@RussellGove @IvanZ 

Could you please humour me and let me know if you are getting delegation warnings on this style of pattern?  I turned my delegation rows down to 1 using a list of 3,000 records and no error is appearing.  I know it says IsBlank is non-delegable for Text in Sharepoint but I am just not seeing the error.  I would appreciate it if you can help me do a test 🙂

 

Filter(
    FPARequests,
    IsBlank(tbYear.Text)=true Or Year = tbYear.Text,
    IsEmpty(cbxRegion.Selected)=true Or Region = cbxRegion.Selected,
    IsBlank(tbCustomer.Text)=true Or Customer tbCustomer.Text,
    IsBlank(tbKeyword.Text)=true Or Keyword = tbKeyword.Text
)

 

View solution in original post

24 REPLIES 24
mdevaney
Super User
Super User

@RussellGove 

Here's my pattern for filtering on multiple fields.  Put this code in the Items property of your gallery.

 

Filter(
    FPARequests,
    If(
        IsBlank(tbYear.Text),
        true,
        Year = tbYear.Text
    ),
    If(
        IsEmpty(cbxRegion.Selected),
        true,
        Region = cbxRegion.Selected
    ),
    If(
        IsBlank(tbCustomer.Text),
        true,
        Customer = tbCustomer.Text
    ),
    If(
        IsBlank(tbKeyword.Text),
        true,
        Keyword = tbKeyword.Text
    )
)

 

---
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."

Does that work with a sharepoint list?

Yes, it works with any datasource.

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

And can it be delegated?

 

I just get  a bunch of red squiggles when i paste in that code. Do you have a working example somewhere?

Can you explain how it works? I  don't see, for example, how it could possibly know what field in my datasource  should be compared with tbYear.Text

 

 

@RussellGove 

I've updated my code in the original post.  See below for response to your questions.

 

"I just get a bunch of red squiggles when i paste in that code"

I missed typing commas after "true" on each line.

 

"How it could possibly know what field in my datasource  should be compared with tbYear.Text"

I didn't put in this comparison initially as I did not see any in your original code.  I have now put in Year, Region, Customer and Keyword.  These names must match the column name in SharePoint.

 

 

 

---
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."

IvanZ
Helper I
Helper I

Check out this video, it demo a fully multiple filtering gallery.

 

https://www.youtube.com/watch?v=pn50AKn3Q1Y&t=82s

Thanskyou. This saved me hours and hours of work trying to do all those nested ifs and elses.

 

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.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

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 (4,207)