Forum Discussion
augustindelaf
9 years agoImpactful Individual
IF formula with multiple conditions
Hi, I would like to create a DAX formula with a IF statement. my formula would be : IF('DATA'[Work Stream ] ="WS 1.1";SUM('DATA'[KPI 2 Monthly Actual]); IF('DATA'[Work Stream ] ="WS 2.1";...
- 9 years ago
a lady from the MS support gave me a solution that seems ok :
---
"
Hi Augustin,
Here are the measures that you will need:
- SelectedValue = IF (ISFILTERED ( Example[Indicator1] ) && HASONEVALUE ( Example[Indicator1] );LASTNONBLANK ( Example[Indicator1]; 0 );"a default value");
- SumValues = SUM(Example[Values]);
- VarKPI2MonthlyTGTR = IF([SelectedValue]="WS"; AVERAGE(Example[Values]); [SumValues]);
In will need to substitute what is in orange with your dimensions.
And here are some interesting documentation:
https://msdn.microsoft.com/en-us/library/ee634396.aspx;
http://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/;"
---
MFelix
9 years agoSuper User
Hi augustindelaf,
I believe that the Switch function will work much better than the IF, try this.
SWITCH(
TRUE();
'DATA'[Work Stream ] = "WS 1.1";
SUM('DATA'[KPI 2 Monthly Actual]);
'DATA'[Work Stream ] ="WS 2.1";
SUM('DATA'[KPI 2 Monthly Actual]);
'DATA'[Work Stream ] ="WS 2.2";
AVERAGE('DATA'[KPI 2 Monthly Actual]);
'DATA'[Work Stream ] ="WS 3.1";
SUM('DATA'[KPI 2 Monthly Actual]);
'DATA'[Work Stream ] ="WS 3.4";
SUM('DATA'[KPI 2 Monthly Actual]);
'DATA'[Work Stream ] ="WS 3.5";
AVERAGE('DATA'[KPI 2 Monthly Actual]);
0)
You can change the final 0 by the default value you want.
Regards
MFelix