Forum Discussion
Anonymous
7 years agoNot applicable
Divide by Zero error
Hi All, I have this measure that's causing error due to divide by zero error. How can I get pass this? % Change = SUMX(Summary, Summary[CQ] - Summary[PYQ]/(Summary[PYQ])) Thanks Ejyks
- Anonymous7 years ago
Think this should work:
% Change = SUMX ( Summary, DIVIDE( (Summary[CQ] - Summary[PYQ] ), //Numerator Summary[PYQ] , //Denominator "If Error, put something here!" //Alternate Result ) )
Anonymous
7 years agoNot applicable
Let's try this one. Basically added in logic that if either the absolute values of the values we need to divide is 0, then we want a 0 there, if not to the normal divide.
Just need to substitute out my generic table and measures for yours:
% Change =
SUMX(
VALUES( Table1[Index] ),
CALCULATE(
IF (
OR (
ABS([Total Item1] ) = 0,
ABS( [Total Item 2]) = 0
),
0,
DIVIDE(
( [Total Item 2] - [Total Item1]),
[Total Item1]
)
)
)
) Anonymous
7 years agoNot applicable
Basically I got confused by the your last formula so I changed the whole formula to use an IF statement and it now works for me. The -1.0 is what gives -100% when converted to percentage.
% Change PYQ = IF(DIVIDE(SUM(Summary[CQ])- SUM(Summary[PYQ]), //Numerator
SUM(Summary[PYQ]) //Denominator
) = -1.0, 0,
DIVIDE(SUM(Summary[CQ])- SUM(Summary[PYQ]), //Numerator
SUM(Summary[PYQ])))