Morning all,
So I do some work with Power BI, and a recent development over there is that you can trick SWITCH() into performing as a nested IF statement.
See this article here for more details:
https://p3adaptive.com/2015/03/the-diabolical-genius-of-switch-true/
The beauty of this is that you can create nested IF statements (that equate to True!) in a format that is much easier to read. And it turns out you can use this same functionality in PowerApps with Switch(true, your conditions and results here). As an example, this is me using it to runs a very complicated Filter over a gallery based on buttons pressed:
Switch(true,
//Category Filter
Not(IsBlank(areaCat)),
Filter(
faqCol,
Or(
areaCat in Type,
areaCat in 'Query On')),
//Filter when Item is selected
Not(IsBlank(suggested)),
LookUp(
faqCol,
suggested.Title in Title),
//Show all Items
Or(IsEmpty('Search Input'),IsBlankOrError('Search Input')),
faqCol,
//Filter based on search input
Filter(
faqCol,
Sum(
ForAll(
Split('Search Input'.Text, " "),
If(
Or(
Result in Ungroup(ForAll(Split('Query Area',";"),Split(Result," ")),"Value"),
Result in Ungroup(ForAll(Split('Query On',";"),Split(Result," ")),"Value"),
Result in Ungroup(ForAll(Split(Title," "),Split(Result," ")),"Value")),
{Count: 1},
{Count: 0}
)
),
Count
) > 0
))
As a nested IF statement this was previously a nightmare to read. I mean, it still is, but hopefully you get the picture!
I don't know if this is a bug or if there are any problems with using SWITCH in this manner, but I hope it helps someone!