Forum Discussion
DAX Measure with Nested IF Statements
Hi,
I'm wondering how I can create a nested if statement on DAX to return a value. If my date falls between A and B, Return Week1, OR if it falls between A and B, Return Week 2... and so on.
Thank you,
Hey,
so it looks similar, but the DAX parser / engine sometimes is not that smart, for this reason use
AND(Issues[Created Date]>= DATE(2017,7,21) ...
instead
Regards
4 Replies
- TheOckieMofoResolver II
You're probably best off using the SWITCH function instead of multiple nest ifs. They will both get you to the promised land, but the SWITCH function is a little cleaner and easier to keep straight.
Here's a couple of blog posts about SWITCH:
https://powerpivotpro.com/2012/06/dax-making-the-case-for-switch/
https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/
Get to know SWITCH. It's definitely a function I use frequently.
- malqinnehRegular Visitor
Thanks so much, this is very helpful! One of the examples provided is almost an identical problem. I had an add-on question that I thought I can append here:
My formula so far is:
Week Opened = SWITCH(TRUE(),
AND(Issues[Created Date]>= 7/21/2017, Issues[Created Date])<= 7/30/2017, "Week 1",
AND(Issues[Created Date]>= 7/31/2017, Issues[Created Date])<= 8/6/2017, "Week 2", "Other")
However, I'm receiving a "DAX comparison operations do not support comparing values of type True/False with values of type Number. Consider using the VALUE or FORMAT function to convert one of the values." error. The [Created Date] column is in fact a date and in the same format. Can you help identify what issue may be?- TomMartensSuper User
Hey,
so it looks similar, but the DAX parser / engine sometimes is not that smart, for this reason use
AND(Issues[Created Date]>= DATE(2017,7,21) ...
instead
Regards
- malqinnehRegular Visitor
Thank you!