Forum Discussion
Switch with dates and text values/format
- 2 years ago
jmetf150 I think you want:
Cond = switch(TRUE(), 'R'[RS]="OT", IF('R'[RDD]<='R'[RCD], "PD", "LLT") ) or Cond = switch('R'[RS], "OT", IF('R'[RDD]<='R'[RCD], "PD", "LLT") )
Greg_Deckler can you explain the difference between both of your solutions and when you would use one over the other?
jmetf150 Well, you would use a "normal" SWITCH statement when you have different values you want to return for different values in a column for example. There's no complex logic required in terms of when you want to return which values. So, let's say you have a column that can contain Pickle, Banana or Cucumber and you want to return 1 for Pickle, 2 for Banana and 3 for Cucumber. This is the second example.
The 1st example, the SWITCH(TRUE() ) statement is used when you have complex criteria, so return 1 if Pickle and the Value is > 30 for example.
Also note that in this specific use case, you could have used an IF statement,
IF( 'R'[RS]="OT" && 'R'[RDD]<='R'[RCD], "PD", "LLT")