Forum Discussion
IFS in DAX
Hello everybody,
I have these data:
| ACT/BUD | Amount | % |
| BUD | 10 | 1 |
| ACT | 5 | 0,461538462 |
| DELTA | -5 | -0,53846154 |
| BUD | 3 | 1 |
| ACT | 1 | 0,461538462 |
| DELTA | -2 | -0,53846154 |
% is actually, what I need to calculate.
I used following formula:
'02 Deníky vše' is the table
- Anonymous6 years ago
Anonymous
For multiple IFs, I would recommend you use a SWITCH function:
%_ = VAR BUD_= 1 VAR ACT_ = SUMX(FILTER('02 Deníky vše',[BUD/ACT]="ACT"),[Amount])/SUMX(FILTER('02 Deníky vše','02 Deníky vše'[BUD/ACT]="BUD"),[Amount]) VAR DELTA_ = ACT_- BUD_ RETURN SWITCH([BUD/ACT], "BUD",BUD_, "ACT",ACT_,"DELTA",DELTA_)Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- amitchandakSuper User
The column name is missing in the filter
SUMX ( '02 Deníky vše'; IF ( '02 Deníky vše'[BUD/ACT] = "ACT";CALCULATE(SUM('02 Deníky vše'[Amount]);FILTER('02 Deníky vše';'02 Deníky vše'[ACT/BUD]="ACT")/SUM('02 Deníky vše'[Amount]);FILTER('02 Deníky vše';'02 Deníky vše'[ACT/BUD]="BUD")); IF ( '02 Deníky vše'[BUD/ACT] = "BUD";1;(CALCULATE(SUM('02 Deníky vše'[Amount]);FILTER('02 Deníky vše';'02 Deníky vše'[BUD/ACT]="ACT")/SUM('02 Deníky vše'[Amount]);FILTER('02 Deníky vše';'02 Deníky vše'[BUD/ACT]="BUD")))-1 ) ) )- AnonymousNot applicable
Hi amitchandak,
thanks for the tip! Unfortunately, I still get the "A function 'FILTER' has been used in a True/False expression that is used as a table filter expression. This is not allowed." error message and it won't work.
- amitchandakSuper User
I did a few more corrections. Format it better to find the error
SUMX ( '02 Deníky vše'; IF ( '02 Deníky vše'[BUD/ACT] = "ACT";(CALCULATE(SUM('02 Deníky vše'[Amount]);FILTER('02 Deníky vše';'02 Deníky vše'[ACT/BUD]="ACT"))/SUM('02 Deníky vše'[Amount]);FILTER('02 Deníky vše';'02 Deníky vše'[ACT/BUD]="BUD")); IF ( '02 Deníky vše'[BUD/ACT] = "BUD";1;(CALCULATE(SUM('02 Deníky vše'[Amount]);FILTER('02 Deníky vše';'02 Deníky vše'[BUD/ACT]="ACT"))/SUM('02 Deníky vše'[Amount]);FILTER('02 Deníky vše';'02 Deníky vše'[BUD/ACT]="BUD"));blank())) -1 )
- AnonymousNot applicable
Anonymous
For multiple IFs, I would recommend you use a SWITCH function:
%_ = VAR BUD_= 1 VAR ACT_ = SUMX(FILTER('02 Deníky vše',[BUD/ACT]="ACT"),[Amount])/SUMX(FILTER('02 Deníky vše','02 Deníky vše'[BUD/ACT]="BUD"),[Amount]) VAR DELTA_ = ACT_- BUD_ RETURN SWITCH([BUD/ACT], "BUD",BUD_, "ACT",ACT_,"DELTA",DELTA_)Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.