Forum Discussion
Koritala
Post Patron
11 months agoDifference b/w Normar Switch & Switch with TURE()
Hi, May I know the Difference b/w a Normal Switch & switch with TURE()? in DAX Which one is the optimistic? Thanks, Srinivas.
- 10 months ago
Hi Koritala ,
Could you let us know if your issue has been resolved or if you are still experiencing difficulties? Your feedback is valuable to the community and can help others facing similar problems.
GeraldGEmerick
Memorable Member
11 months agoKoritala The "normal" SWITCH statement takes a value as the first parameter and then each pair of statements after that simply checks if that value equals the first value in the pair of statements and if so returns the second value in the pair of statements. For example:
SWITCH(
MAX( 'Table'[Color] ), //first parameter this is the value to check
"Red", 1, // if the first parameter equals "Red" then return 1
"Blue", 2 // if the first parameter equals "Blue" then return 2
3 // otherwise, return 3 if the color is neither red or blue
)
SWITCH TRUE is a more flexible version where each pair of statements after the first parameter (TRUE) you can have a logical test which, if it evaluates to true, returns the corresponding value. For example:
SWITCH(
TRUE(),
MAX( 'Table'[Color] ) = "Red" && SUM( 'Table'[Value] ) < 100, 1,
MAX( 'Table'[Color] ) = "Red" && SUM( 'Table'[Value] ) < 200, 2,
3
)