cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ianhilltegna
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
v-bofeng-msft
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
v-bofeng-msft
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
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

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (24,864)