If you’ve ever tried to use an IIF statement expression to fix an error received by dividing by zero, you probably still received the divide by zero error message. Very frustrating.
An expression like this returns an error when Sum(Fields!Beta.value) = 0:
=sum(Fields!Alpha.Value)/sum(Fields!beta.Value)
So you, being the critical thinker that you are, try the following:
=iif(sum(Fields!Beta.Value)=0,0,sum(Fields!Alpha.Value)/sum(Fields!Beta.Value))
Alas, this will not work. Even though SSRS may evaluate your expression as true, it still will attempt to resolve the false part of your expression, which gives you the divide by zero error.
To get around this infuriating issue Microsoft should have dealt with in the first place, try this:
=iif(sum(Fields!Beta.Value)=0,0,sum(Fields!Alpha.Value)/iif(sum(Fields!Beta.Value)=0,1,sum(Fields!Beta.Value))
This solution should fix any issues you have dividing by zero.
thanks for this. You’re missing one last paren though in the final expression.
Hey..thank you so much for saving my time. It worked like a charm!
You’re welcome!