Forum Discussion
philippa_f
4 years agoFrequent Visitor
DAX for SWITCH statement on calculated column - how to include VALUE function?
Hi I have a calculated column in my table that works out number of Days to Expiry, and I then need another calculated column to allocate descriptors based on that number to give me 'Expiry Status...
- 4 years ago
Thanks everyone for trying to help. I have just got it to work using the following:
Expiry Status =SWITCH (TRUE(),'MyTable'[DaystoExpiry] =BLANK(), "No Exp. date",'MyTable'[DaystoExpiry] < 0, "Expired",'MyTable'[DaystoExpiry] < 366, "Less than 1yr",'MyTable'[DaystoExpiry] > 365, "More than 1yr")I think the issue was the order of my logic, together with using "" when I should have been using BLANK().Got there in the end with your combined help 🙂
FarhanAhmed
Community Champion
4 years agoKindly check the datatype of "'MyTable'[DaystoExpiry]"
When you are calculating null/blank values for MyTable'[DaystoExpiry] it is better to return BLANK not "" which causes to enforce column to Text datatype.
philippa_f
4 years agoFrequent Visitor
Hi FarhanAhmed
Thanks so much for getting back to me. I did substitute BLANK in the code above instead of "" - was this what you meant?
Like this:
Expiry Status = SWITCH(
TRUE (),
'MyTable'[DaystoExpiry] = BLANK, "No Exp. date",
'MyTable'[DaystoExpiry] < 0, "Expired",
'MyTable'[DaystoExpiry] > 366, "Exp. date > 1 yr",
"Exp. date <= 1 yr"
But it is still not working, giving me an incorrect syntax error. Can you spot what I have done wrong? Many thanks in advance!