The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hello to all,
So , I will try to explain my problem as precise as possible.
I would like to develop a measure with multiple conditions to determine the situation of the market :
I have first develop 2 others measures TM[TM3MR%VARPY] and TM[TM12MR%VARPY] that represent
Then I would like to express a DAX function for multiple conditions to determine the situation the market :
If TM[TM3MR%VARPY]>0 && TM[TM12MR%VARPY]<0,"RECOVERY"
if TM[TM3MR%VARPY]>=0,02 && TM[TM12MR%VARPY]>=0,02,"EXPANSION"
if TM[TM3MR%VARPY]>TM[TM12MR%VARPY] && TM[TM3MR%VARPY]<0,02,"PEAK"
if TM[TM3MR%VARPY]<[TM12MR%VARPY],"MATURITY"
Then I try to use the "SWITCH" DAX function for multiple conditions but seems that it's something that don't master
see below
Solved! Go to Solution.
You are missing "(" after SWITCH. Also, I would first store your two measures as variables and then use the variables in the SWITCH evaluations. The way it is written will cause a lot of recalculation. Partial example below (note that you should not include the table name when referencing measures so other knows it is a measure and not a column reference).
Measure =
VAR varpy3M = [TM3MR%VARPY]
VAR varpy12M = [TM12MR%VARPY]
RETURN
SWITCH (
TRUE (),
varpy3M > 0
&& varpy12M < 0, "RECOVERY",
varpy3M >= 0.02
&& TM[TM12MR%VARPY] >= 0.02, "EXPANSION",
"Other"
)
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
You are missing "(" after SWITCH. Also, I would first store your two measures as variables and then use the variables in the SWITCH evaluations. The way it is written will cause a lot of recalculation. Partial example below (note that you should not include the table name when referencing measures so other knows it is a measure and not a column reference).
Measure =
VAR varpy3M = [TM3MR%VARPY]
VAR varpy12M = [TM12MR%VARPY]
RETURN
SWITCH (
TRUE (),
varpy3M > 0
&& varpy12M < 0, "RECOVERY",
varpy3M >= 0.02
&& TM[TM12MR%VARPY] >= 0.02, "EXPANSION",
"Other"
)
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hi Pat,
Finally it works , I found my mistake (Stupid mistake 😁)
Thank you again for your help !
Dear Pat,
thank you for your answer.
I tried your solution but I have another problem now. When I want to vizualize my measure , Power BI told me that
SWITCH does not support comparing values of type TRUE/FLASE with values of type text.
Consider using the value or format function to convert one of the values
So I convert the text results with value function but I have still the same message.
Please see below my measure:
It's hard to tell based on this information. The most likely issue is that you have to get the order of these correct. Switch will stop on the first result that returns true. If you can't work out what is happening I suggest you write each component as a simpnle measure and see what they return.
User | Count |
---|---|
15 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
24 | |
20 | |
12 | |
9 | |
7 |