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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
PaulD1
Community Champion
Community Champion

@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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

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

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,051)