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 🙂
philippa_f
4 years agoFrequent Visitor
Hi AUDISU
Thanks. I tried this, but it gives a result of 'Expired' for every line of data, although there are definitely some that should be in each category. Any idea what I am doing wrong? Data type is text, if I change it to numbers I just get an error for everything, with a message saying Cannot convert value 'Expired' of type Text to type Integer.
I really appreciate you taking the time to help with this.
Philippa
AUDISU
Resolver III
4 years agoHi Philippa,
Can I see your DAX formula?
Thanks
- philippa_f4 years agoFrequent VisitorSure:Expiry Status =VAR NoofDays = SUM('MyTable'[DaystoExpiry])RETURNSWITCH(TRUE() ,NoofDays = 0, "No Exp. date",NoofDays < 0, "Expired",NoofDays > 366, "Exp. date > 1 yr","Exp. date <= 1 yr")
- AUDISU4 years ago
Resolver III
Hi Philippa,
Please check data type of 'MyTable'[DaystoExpiry] column.
If it is not in number format change it to number.
Thanks