web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / If statement inside fi...
Power Apps
Answered

If statement inside filter condition

(0) ShareShare
ReportReport
Posted on by 3

Hello!

 

  I'm trying to have an if statement inside a filter statement, and keep getting delegation warnings. I'm wondering if anyone can point me in the right direction!

 

Filter(MyTable,If(DropDown.Selected.Value = "All",true,MyTableColumn = DropDown.Selected.Value))

 

Anyone know how to get this right? Has to not have delegation issues! Also, I know that I could do the If statement outside the filter, but in my actual project there are many dropdowns all needing this same treatment, so I end up with this huge branching logic formula - which I'm trying to avoid. Thanks!

Categories:
I have the same question (0)
  • Verified answer
    mdevaney Profile Picture
    29,989 Moderator on at

    @JoeCochran 

    A quick re-write of this formula will do the trick!

    Filter(
     MyTable, 
     DropDown.Selected.Value = "All"
     Or MyTableColumn = DropDown.Selected.Value
    )

     

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

  • Pstork1 Profile Picture
    68,717 Most Valuable Professional on at

    Unfortunately, embedded IF() statements don't really work inside a Filter.  You can create an IF() that executes different Filters based on a condition though.  What you want is this

    IF(DropDown.Selected.Value = "All",MyTable,Filter(MyTable,MyTableColumn = DropDown.Selected.Value))
  • Kiki1 Profile Picture
    30 on at

    A year later this helped me. Thanks 

  • nikhil17_92 Profile Picture
    6 on at

    Thanks a lot! Helped me reduce a long code with if conditions to an optimized short code.

  • Community Power Platform Member Profile Picture
    on at

    2 years later we don't have any possibility to use the if statement inside filter objects
    ----------------

    Example:

     

    Filter( MyColors,

    If(dropdownColor.Value = "red", color.Value = "red")

    )

  • Pstork1 Profile Picture
    68,717 Most Valuable Professional on at

    Since you can accomplish the same thing by using the If() on the outside I doubt you will see that change.

  • Community Power Platform Member Profile Picture
    on at

    Hello,

    I've a system with multiple conditions... if I follow your solution, I've the next awful result:

     

    if(condition,
     filter,
     if(condition,
     filter,
     if(condition,
     filter,
     if(condition,
     filter,
     table
     )
     )
     )
    )

     

     

    My use case is a bit special because I use a sharepoint with 3 dropdown and 1checkbox, ticked I want show only elements with true value else all elements.

    For the 3 dropdown, I want filter the items together if each of them has a value, like being able to filter if there is only 1 that has a value. If none has a value then the filter doesn't apply and return the table filtered by the checkbox or no:

     

     

    I've an example of my list with 3 fake tasks:

    [{

        "Title": "one",

        "Category": "A",

        "ShowInTheMeeting": false,

        "Status": "Closed",

        "Assign to":UserObj

    },

    {

        "Title": "two",

        "Category": "B",

        "ShowInTheMeeting": false,

        "Status": "Pending",

        "Assign to":UserObj

    },

    {

        "Title": "three",

        "Category": "A",

        "ShowInTheMeeting": true,

        "Status": "Opened",

        "Assign to":UserObj

    }].

     

     

    That's why I think a filter with a conditionnal value is necessary, because you didn't to repeat your code, or a possibility to create a function on the page without "cheating" with the components to compensate the lack of possibilities

  • Community Power Platform Member Profile Picture
    on at

    How to if condition two filter its possible?

  • nmasmo Profile Picture
    91 on at

    @mdevaney  Great solution, thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard