Forum Discussion
Switch/IF condition ignores zero
Hi Everyone,
While using DAX switch or if, condition ignores zero values.
Eg. In my case Im calculating Hour >=0 && Hour<4, it ignores zero values and executing values greater than zero.
I also tried Hour=0, even then it ignores the zero value.
Here is screenshot.
Please let me know how to overcome this.
Thanks.
Hi Anonymous ,
You also could refer to below calculated column for details.
Column = switch(TRUE(),ISBLANK('Table'[Hour]),0,'Table'[Hour]>=0 && 'Table'[Hour]<4,1,'Table'[Hour]>=4,0)You could refer to BLANK-is-caught-as-0-in-Columns for details.
Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- az38Community Champion
Hi Anonymous
what is the column Hour? is it calculated? are you sure it is exactly zero, not rounded decimal like 0.0000001?
- AnonymousNot applicable
Hi az38 , Thanks for response.
I understand the problem, in my condition I initially put criteria for blank() =0 (where 0 is taken as blank), so it has taken as zero, even if I try to change the criteria to multiple times it was taking into effect.
So I changed zero values to 1 in power query(Where zero values needs to taken into consideration not blank values) and calculated with switch condition with same expression it worked.
- daxCommunity Support
Hi Anonymous ,
You also could refer to below calculated column for details.
Column = switch(TRUE(),ISBLANK('Table'[Hour]),0,'Table'[Hour]>=0 && 'Table'[Hour]<4,1,'Table'[Hour]>=4,0)You could refer to BLANK-is-caught-as-0-in-Columns for details.
Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- az38Community Champion
Anonymous
sorry, I also see, you return 0 when Hour is plank. try to replace your conditions in switch like
SWITCH(TRUE(), [Hour] >=0 && [Hour] < 4, 1, 0 )