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 Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (2,387)