You should be able to rewrite your formula to act as a simple aggregation calculation, rather than a row-level calculation. Like this:
IF SUM() = 0 AND SUM() = 0 then 0
ELSEIF SUM() = 0 AND SUM() > 0 then 100
ELSEIF SUM() = 0 AND SUM() > 0 THEN -100
(SUM(-) / SUM()) * 100
That way, it will use whatever is the current level of detail when it performs the aggregations.
By the way, two observations:
- Your exceptions yield numbers in the range -100 to +100, but your final calculation will yield a number in the range -1.0 to +1.0. I added * 100 to my ELSE line to correct for this.
- You don't really need the third condition, the one that outputs -100, because the same result will be obtained by the ELSE computation.
Hope this helps!