Reputation: 55
I know similar questions have been asked. However, I have not found anything that exactly helps me out in my situation.
I need to avoid divide by zero but before I do a divide with another column value, I am performing a math calculation:
=Sum((Fields!col1.Value) - Sum(Fields!col2.Value) / Sum(Fields!col2.Value))
I basically want to do a subtraction first, then a divide but I am unable to get the expression or the custom code to work for me. And before I spend too many hours on this one, I figured I would reach out for help.
This is the code I have come up with so far and it works, but I want the column to show nothing instead of 0:
=IIf(Sum(Fields!LWCasesBudget.Value) = 0, 0,
Sum(Fields!LWShipQuantity.Value) - Sum(Fields!LWCasesBudget.Value))/
IIf(Sum(Fields!LWCasesBudget.Value) = 0, 1, Sum(Fields!LWCasesBudget.Value))
Upvotes: 0
Views: 219
Reputation: 485
It seems like you are happy with your calculation. If the 0 is the only issue then try and replace the 0 with the word "nothing".
Example:
=IIf(Sum(Fields!LWCasesBudget.Value) = 0, nothing,
Sum(Fields!LWShipQuantity.Value) - Sum(Fields!LWCasesBudget.Value))/
IIf(Sum(Fields!LWCasesBudget.Value) = 0, 1, Sum(Fields!LWCasesBudget.Value))
Hope that helps.
Upvotes: 1