cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
enswitzer
Helper II
Helper II

Filter based off multiple toggles

Spoiler
I am attempting to filter based off two toggles.
1) Active User (who is currently using the form)
2) Active Projects (status of the project)

I got it to work for one, but the Active User Toggle is telling me I'm using and invalid argument type, although I thought I was using the same argument type as the other toggle, so I'm slightly confused.

If('Active User Toggle'.Value, 
    Filter(
        Sort('Project Portfolio - Project Input', Title), //just sorting the output
        'Project Lead'.Email = User().Email),  //filter for the active user toggle (doesn't like)
    If(
        'Active Projects Toggle'.Value, 
        Filter(
            Sort('Project Portfolio - Project Input', Title),  //just sorting the output
            'Project Status'.Value = "Active"),  //filter for the active project toggle
        Sort('Project Portfolio - Project Input', Title)))​
1 ACCEPTED SOLUTION

Accepted Solutions

@enswitzer 

For a little more manageable formula, you might want to also consider:

Sort(
    Filter('Project Portfolio - Project Input', 
        If('Active User Toggle'.Value, 'Project Lead'.Email = User().Email, true) &&
        If('Active Projects Toggle'.Value,  'Project Status'.Value = "Active", true)
    ),
    Title
)

It's not always a great thing to have multiple filters in a formula - if you decide you need to change the filter criteria, or add more, if you have multiple filters, you will need to change all of them.  When you simplify (I like to call it refactoring) you get to one filter statement that is easy to add to or change if needed.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

4 REPLIES 4
hantsjoel
Resolver II
Resolver II

Hi @enswitzer,

 

Do you need to apply both toggle filters at the same time? At the moment you will only applying your Project Status filter if the 'Active User Toggle' is false.

 

Try building out each case in the If statement:

 

If(

   !'Active User Toggle'.Value && !'Active Projects Toggle'.Value,

   Sort('Project Portfolio - Project Input', Title),

   'Active User Toggle'.Value && !'Active Projects Toggle'.Value,

   Filter(

           Sort('Project Portfolio - Project Input', Title),

           'Project Lead'.Email = User().Email

    ),

    !Active User Toggle'.Value && 'Active Projects Toggle'.Value,

    Filter(

            Sort('Project Portfolio - Project Input', Title),

            'Project Status'.Value = "Active"

     ),

     Filter(

            Sort('Project Portfolio - Project Input', Title),

            'Project Status'.Value = "Active" && 'Project Lead'.Email = User().Email

      )

)

 

Hope that helps!

Joel

@enswitzer 

For a little more manageable formula, you might want to also consider:

Sort(
    Filter('Project Portfolio - Project Input', 
        If('Active User Toggle'.Value, 'Project Lead'.Email = User().Email, true) &&
        If('Active Projects Toggle'.Value,  'Project Status'.Value = "Active", true)
    ),
    Title
)

It's not always a great thing to have multiple filters in a formula - if you decide you need to change the filter criteria, or add more, if you have multiple filters, you will need to change all of them.  When you simplify (I like to call it refactoring) you get to one filter statement that is easy to add to or change if needed.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

@RandyHayes 

Just an observation, but while the formula is more manageable, won't placing the IFs inside the filter make this non-delegable?

In this specific case, that may not be an issue and the User().Email predicate may be making this non-delegable already, but that could be solved by assigning User().Email to a variable and referencing that.

The use of a choice field:

'Project Status'.Value = "Active"

is possibly another cause of non-delegation - I avoid Choice Fields (and SharePoint!) so don't know if that is something that has been improved in recent updates.

@PaulD1 

Yes - it was purely conceptual.  If delegation is an issue, then it would be written differently.  And yes, the User function would typically be put outside of the filter. 

Delegation on complex columns is not so much a concern any longer as they can now delegate those queries.

 

Incidentally, if I was concerned over delegation issues, I would rewrite to this formula:

With({lclUser: User().Email},
    Sort(
        Filter('Project Portfolio - Project Input', 
            ('Active User Toggle'.Value || 'Project Lead'.Email = lclUser) &&
            ('Active Projects Toggle'.Value || 'Project Status'.Value = "Active")
        ),
        Title
    )
)

Oddly enough, it is kind of the same filter criteria, but PowerApps can't parse the If statements into this to be delegable...maybe one day it will.

 

Thanks for commenting!

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (4,025)