Forum Discussion

BICons's avatar
BICons
New Member
2 years ago
Solved

Substract two metrics conditionally

Hello,

 

I have two metrics, one of this is Current sales and the other is Previous year sales, I need to subtract this two metrics depending on wheather Current Sales > 0 && Previous year sales > 0 or not. Te problem is that the total is showing 0 because it is comparing the total sales and the previous Year sales Total, while what I want is the sum of each rows.
This is the way I am calculating in DAX:

Churn = IF([SumTotalSales] = 0 && [SumTotalSalesPreviousYear] > 0,  [SumTotalSalesPreviousYear], 0)
This is the table that I have which is not what I want:

 


 

I have tried with these other two metrics:
1.- 
Churn = SUMX(
    VALUES('Calendar'[Año]),
    IF([SumTotalSales] = 0 && [SumTotalSalesPreviousYear] > 0, [SumTotalSales] - [SumTotalSalesPreviousYear],0))
2.- 
Churn2 =
SUMX(
    ADDCOLUMNS(
        'Sales',
        "Total",
        IF(
            [SumTotalSales] = 0 && [SumTotalSalesPreviousYear] > 0,
            [SumTotalSales] - [SumTotalSalesPreviousYear],
            0
        )
    ),
    [Total]
)
 
But again they don't work.
 
Thank you for your help!
 
Regards!!
 


 

2 Replies