Forum Discussion
sum with condition
- 4 years ago
See if this works:
Mov_cond_PK = SUMX ( VALUES ( Tabella[Product Number] ), IF ( [Initial_PK_2] > 0, CALCULATE ( SUM ( Tabella[moving_PK] ) ), 0 ) )Without the CALCULATE, there is no context transition performed, which means the sum of [moving_PK] is done over all the product numbers in the current filter context rather than just the product number from the row context of the SUMX iterator.
If you define SUM ( Tabella[moving_PK] as a measure SumMovingPK, then you don't have to worry about including the extra CALCULATE (since it's included implicitly) and you can write
Mov_cond_PK = SUMX ( VALUES ( Tabella[Product Number] ), IF ( [Initial_PK_2] > 0, [SumMovingPK] ) ), 0 ) )
See if this works:
Mov_cond_PK =
SUMX (
VALUES ( Tabella[Product Number] ),
IF ( [Initial_PK_2] > 0, CALCULATE ( SUM ( Tabella[moving_PK] ) ), 0 )
)
Without the CALCULATE, there is no context transition performed, which means the sum of [moving_PK] is done over all the product numbers in the current filter context rather than just the product number from the row context of the SUMX iterator.
If you define SUM ( Tabella[moving_PK] as a measure SumMovingPK, then you don't have to worry about including the extra CALCULATE (since it's included implicitly) and you can write
Mov_cond_PK =
SUMX (
VALUES ( Tabella[Product Number] ),
IF ( [Initial_PK_2] > 0, [SumMovingPK] ) ), 0 )
)