Forum Discussion
Brettacus
3 years agoFrequent Visitor
Multiple If Statements DAX
Hello, I have been using Power Bi for a few months and I am just starting to get into Dax. Currently I have a report and I only want it to show data for the current quarter plus the previous two ...
- 3 years ago
Brettacus , please try this measure.
Last 3 = var _to=TODAY() return SWITCH(QUARTER(_to), 1, IF(AND(YEAR(_to)-1=YEAR([DATE]),OR(QUARTER([Date])=4,QUARTER([Date])=3)),1,IF(AND(QUARTER(_to)=QUARTER([Date]),YEAR(_to)=YEAR([Date])),1,0)), 2, IF(AND(YEAR(_to)-1=YEAR([DATE]),QUARTER([Date])=4),1,IF(AND(OR(QUARTER(_to)=QUARTER([Date]),QUARTER(_to)-1=QUARTER([Date])),YEAR(_to)=YEAR([Date])),1,0)), IF(AND(YEAR([Date])=YEAR(_to),OR(QUARTER(_to)=QUARTER([Date]),OR(QUARTER(_to)-1=QUARTER([Date]),QUARTER(_to)-2=QUARTER([Date])))),1,0) )
Brettacus
3 years agoFrequent Visitor
I believe I figured out why the nested if will not work, but I can't figure out how to solve for it.
I believe it is because Quarter([Date])=4 is used twice and can only be true once, so depending what order i put it in one of the scenarios will be missing that quarter because the the value gets changed from true to false depending on the order I place it in.
Hoping this additional context can help.