cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

Where is my logical failing? (If, Filter, Switch)

Hey friends! I'm trying to build a simple search of a gallery that's filtered by two toggles:

 

Screen Shot 2020-05-14 at 12.06.01 PM.png

The goal would be something like this:

 

 

If(

And(EXPIRATIONFILTER.Value = false,INACTIVEFILTER.Value = true),  SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending),

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = true),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = false), Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

And(EXPIRATIONFILTER.Value = false,INACTIVEFILTER.Value = false),  Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending)

)

 

 

But I'm getting an error here:

 

 

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = false), Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

 

 

I feel like there's a logical fail I'm not seeing. Re-ordering the statements doesn't help.

 

But this works:

 

 

If(

And(EXPIRATIONFILTER.Value = false,INACTIVEFILTER.Value = true),  SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending),

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = true),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = false), SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

And(EXPIRATIONFILTER.Value = false,INACTIVEFILTER.Value = false),  Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending)

)

 

 

So adding Filter to the third statement is where things are breaking.

 

For the heck of it, I've also written two working Switch statements, but I can't get them to work together:

 

 

Switch(EXPIRATIONFILTER.Value, true, SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending), false, SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending))

 

 

 

Switch(INACTIVEFILTER.Value, false, Search(Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SEARCHPARTNERS.Text,"Title"), true, Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"))

 

 

Any help would be GREATLY appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @ianhilltegna :

Firstly, let me explain why you encounter the error.

The key is formula syntax error.

The result of this code is two tables ,but a gallery can only have one data source.

 

Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending)

 

The correct way is to combine these two functions:

 

SortByColumns(Search(Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending)

 

Secondly,the reason that the correctly allowed code can run is that the second table is defaulted as the result of the four conditions are not met.

Four conditions are not satisfied:

 

SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending)

 

Finally, I suggest you try this code:

 

If(

And(EXPIRATIONFILTER.Value = false,INACTIVEFILTER.Value = true),  SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending),

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = true),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = false),SortByColumns(Search(Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

And(EXPIRATIONFILTER.Value = false,INACTIVEFILTER.Value = false),SortByColumns(Search(Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending)

)

 

In addition,I think this link will help you a lot:

If and Switch functions in Power Apps

Best Regards,

 Bof

View solution in original post

2 REPLIES 2
Community Support
Community Support

Hi @ianhilltegna :

Firstly, let me explain why you encounter the error.

The key is formula syntax error.

The result of this code is two tables ,but a gallery can only have one data source.

 

Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending)

 

The correct way is to combine these two functions:

 

SortByColumns(Search(Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending)

 

Secondly,the reason that the correctly allowed code can run is that the second table is defaulted as the result of the four conditions are not met.

Four conditions are not satisfied:

 

SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending)

 

Finally, I suggest you try this code:

 

If(

And(EXPIRATIONFILTER.Value = false,INACTIVEFILTER.Value = true),  SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending),

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = true),SortByColumns(Search('CONTENT PARTNERS',SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

And(EXPIRATIONFILTER.Value = true,INACTIVEFILTER.Value = false),SortByColumns(Search(Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SEARCHPARTNERS.Text,"Title"),"EXPIRES",Descending),

And(EXPIRATIONFILTER.Value = false,INACTIVEFILTER.Value = false),SortByColumns(Search(Filter('CONTENT PARTNERS',!("Inactive" in 'ACTIVE ONBOARDING INACTIVE')),SEARCHPARTNERS.Text,"Title"),"WHENUPDATED",Descending)

)

 

In addition,I think this link will help you a lot:

If and Switch functions in Power Apps

Best Regards,

 Bof

View solution in original post

That solved it! Thank you!

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (47,050)