Forum Discussion
DAX SWITCH STATEMENT not working properly
- 6 years ago
Hi Anonymous ,
Based on my test and reasearch, I have added a filter in your [Construction Income (Budget)] measure and now it can show the correct result:
Construction Income (Budget) = CALCULATE(SUM('Budget For Meters'[Budget]), FILTER(ALL('Budget For Meters'),'Budget For Meters'[Description] = "1.Construction Income"))Attached the modifed dummy file, please check it: Dummy.pbix
Best Regards,
Yingjie LiIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Here you go.
here's how SWITCH() is supposed to work for your scenario (there are other options too)
SWITCH( TRUE(),<first test>,"first result",<second test>,"second result",...,"alternative result")
- Anonymous6 years agoNot applicable
Actually, I gave you wrong code. This is right one.
- lbendlin6 years ago
Super User
You are using CALCULATE() without any filter context modifiers. That means the calculation will only work on the current context of your visual which is very likely not what you want to do (and which doesn't really need Calculate). What are you actually trying to calculate?
- Anonymous6 years agoNot applicable
Sorry for late response. What do you mean by I am using CALCULATE () without any filter context modifiers? (Sorry again I am a beginner of Power BI.) Basically, I created this measure compare budget and actual like how much actual is different from budget and representing as percentage. The thing is, without SWITCH statement, my code is working. I got a number I want. However, when I add SWITCH statement, it is not working. I am not sure why this is happening.