Forum Discussion
Switch with &&& and ||
- 7 years ago
I think this might just be an order of operations issue I think that the logical AND is evaluated first, then the OR.
So effectively you have: condition1 || ( condition2 && condition3) || condition4
Whereas I think you want: (condition1 || condition2 ) && (condition3 || condition4)
I think adding extra brackets to force the order of operation you want might fix this:
CY Activity = SWITCH( TRUE(), ([1. Jan v2] = 3 || [1. Jan v2] = 5 ) && ([1. Feb v2] = 3 || [1. Feb v2] = 5 ) , 1, 0)
I often use extra bracket if I have multiple logical AND/OR combinations to clarify the ordering
I think this might just be an order of operations issue I think that the logical AND is evaluated first, then the OR.
So effectively you have: condition1 || ( condition2 && condition3) || condition4
Whereas I think you want: (condition1 || condition2 ) && (condition3 || condition4)
I think adding extra brackets to force the order of operation you want might fix this:
CY Activity = SWITCH( TRUE(), ([1. Jan v2] = 3 || [1. Jan v2] = 5 ) && ([1. Feb v2] = 3 || [1. Feb v2] = 5 ) , 1, 0)
I often use extra bracket if I have multiple logical AND/OR combinations to clarify the ordering
Champion!
d_gosbell wrote:I think this might just be an order of operations issue I think that the logical AND is evaluated first, then the OR.
So effectively you have: condition1 || ( condition2 && condition3) || condition4
Whereas I think you want: (condition1 || condition2 ) && (condition3 || condition4)
I think adding extra brackets to force the order of operation you want might fix this:
CY Activity = SWITCH( TRUE(), ([1. Jan v2] = 3 || [1. Jan v2] = 5 ) && ([1. Feb v2] = 3 || [1. Feb v2] = 5 ) , 1, 0)I often use extra bracket if I have multiple logical AND/OR combinations to clarify the ordering