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

If statement inside filter condition

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!

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

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

View solution in original post

8 REPLIES 8
mdevaney
Super User
Super User

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

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


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

A year later this helped me. Thanks 

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

M_DVF
Regular Visitor

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

)

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



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

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

Sujikumar
Advocate II
Advocate II

How to if condition two filter its possible?

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.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

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 (6,530)