March 28, 2012 at 4:12 am
I keep getting the following error: "rsRuntimeErrorInExpression The value expression for the textbox contains an error: Attempted to divide by zero.".
I've tried this:
=IIF(ROUND(((Fields!TG___2012_YTD.Value - Fields!TG___2011_YTD.Value)/Fields!TG___2011_YTD.Value)*100,1) & " % " IS NOTHING,"Null",ROUND(((Fields!TG___2012_YTD.Value - Fields!TG___2011_YTD.Value)/Fields!TG___2011_YTD.Value)*100,1) & " % ")
And this:
=IIF((Fields!TG___2012_YTD.Value) = 0,0,
((Fields!TG___2012_YTD.Value) - (Fields!TG___2011_YTD.Value)/Fields!TG___2011_YTD.Value) *100)
Can anyone see what I'm missing?
March 28, 2012 at 4:24 am
=IIF((Fields!TG___2012_YTD.Value) = 0,0,
((Fields!TG___2012_YTD.Value) - (Fields!TG___2011_YTD.Value)/Fields!TG___2011_YTD.Value) *100)
the problem on the above is the second 0 as your still passing in 0 to divide by, change it to 1 so that it divides by 1 to get itself
March 28, 2012 at 4:40 am
Same Problem?
for e.g.
My Field!TG__2012_YTD.Value is '0' and
Field!TG__2011_YTD.Value is 646?
March 28, 2012 at 4:44 am
as your dividing by ytd2011 thats the one you need to check is 0, not ytd2012, missed that at first look
March 28, 2012 at 5:10 am
It now gives me the answer 1. When the answer should be 100. (from the calculation)?
March 28, 2012 at 7:33 am
what is your expression with the change to ytd2011 and what value fro ytd2012 is being used 0 still?
March 29, 2012 at 8:27 am
I have managed to get the following formula working in Excel where 2011 = 0 and 2012 = 9454 and it does not give me a divide by zero error until I put this in SSRS!
=IIF(Fields!TG___2011_YTD.Value = Fields!TG___2012_YTD.Value, 0,IIF(Fields!TG___2011_YTD.Value <= 0,IIF(Fields!TG___2012_YTD.Value > 0, "8", 0),
(Fields!TG___2012_YTD.Value - Fields!TG___2011_YTD.Value)/(Fields!TG___2011_YTD.Value)))
????
March 30, 2012 at 4:33 am
I think the issue you're having is that SSRS evaluates the entire expression prior to doing the comparsions, so you'll always be dividing by zero. I wrote custome code to get around it and just call that rather the using the IIF statement.
May 9, 2012 at 3:17 pm
I've been having this same issue and tried following all the examples given and could not get it working.
My method of Fixing this was I used the general calculation, = IIF (Fields!Field1.value = 0, 0, (Fields!Field2.value / Fields!1.value)...... I would still get the error.
I then went to the Text Box Property where I have my calculation and set the visibility to show or hide based on expression and set it to: = IIF (Fields!Fields1.value = 0, True, False)
It may not be the fanciest way but it works for me. 😉
May 9, 2012 at 7:08 pm
Add custom code to rdl (report properties --> code pane):
Public Function DivideBy(ByVal Numerator, ByVal Denominator)
If Denominator = 0 Then
DivideBy = 0
Else : DivideBy = Numerator / Denominator
End If
End Function
Add to expression as:
=Code.DivideBy(Fields![Numerator].Value, Fields![Denominator].Value)
Where you replace [Numerator] and [Denominator] with the field values you want to divide
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply