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

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
Highlighted
Super User III
Super User III

Re: Filter based off multiple toggles

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

4 REPLIES 4
Highlighted
Resolver I
Resolver I

Re: Filter based off multiple toggles

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

Highlighted
Super User III
Super User III

Re: Filter based off multiple toggles

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Highlighted
Super User
Super User

Re: Filter based off multiple toggles

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

Highlighted
Super User III
Super User III

Re: Filter based off multiple toggles

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,689)