May 31, 2012 at 2:34 pm
Below is my current expression. It takes Canc_Files column from AT_CurrentCycle dataset and substracts that from Canc_Files_tly in the "AT_PreviousCycle" dataset. The result is then divided by Canc_Files in the AT_CurrentCycle. I have several lines on my report like this. However, I am running into NaN or Infinity. Can anyone give advice on how to write an expression that allows for divide by zero issues?
=(Sum(Fields!Canc_Files.Value, "AT_CurrentCycle") - Sum(Fields!Canc_Files_tly.Value, "AT_PreviousCycle")) / Sum(Fields!Canc_Files.Value, "AT_CurrentCycle")
May 31, 2012 at 2:40 pm
I embed the following code into the report in Report Properties >> Code
Public Function DivideBy(ByVal Exp1, ByVal Exp2)
If Microsoft.VisualBasic.IsNumeric(Exp1) And Microsoft.VisualBasic.IsNumeric(Exp2) Then
If Exp2 = 0 Then
DivideBy = 0
Else: DivideBy = Exp1/Exp2
End If
Else
DivideBy = "N/A"
End If
End Function
In your report you call the function like
code!DivideBy(YourNumeratorValueHere,YourDenominatorValueHere)
This returns N/A when one of the values is not a number, and zero when the denominator is zero, and the calculated value when both are numbers.
May 31, 2012 at 3:04 pm
Hi Daniel,
Thanks so much for your reply. Just to ask a super-newbie question - How to I create the "yournumeratorhere" and "yourdenominatorhere" information? I'm just not sure how to plug the code I've posted into that area. Thanks again for your help and patience 🙂
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply