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 Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

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

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,529)