Forum Discussion
heathernicole
10 years agoContinued Contributor
SWITCH statement in DAX using a "between this value and this value" as a filter?
VERY new to DAX - I think my issue is I haven't nailed down how to ask the right question yet - which hinders research for an answer: Trying to create an IF (or a Switch) statement If "this v...
greggyb
10 years agoResident Rockstar
SWITCH() can only compare to a constant, this is true, but you can still utilize it to avoid nested IF()s for a cleaner syntax and easier modification.
Simply match against the constant TRUE(), then each of your tests (which are Boolean expressions anyway) are tested for equality with TRUE():
// DAX
// SWITCH() instead of nested IF() - works in measure, column, or table
SwitchTrue =
SWITCH(
TRUE()
,<boolean expression>, <result if true>
,<boolean expression>, <result if true>
, ..., ...
,<else condition - no trues above>
)asocorro
10 years agoSkilled Sharer
Nice!
- greggyb10 years agoResident Rockstar
Blow someone's mind:
// DAX // Works anywhere // Don't do this without a good reason SWITCH( FALSE() ,<boolean>, <result if boolean is false) .... ,<result if all boolean expressions above are false> )Then you're testing each expression for equality with FALSE(). So tests that fail get their result evaluated.
- TealCanady10 years agoAdvocate II
A few reference articles for this method in case you are interested.
DAX making the case for switch
The diabolical genius of switch-true
Teal