我想在预览报告(ssrs)时避免NaN值。 我使用了自定义代码。
Public Dim TotalAmount As Double = 0
Public Dim ThisValue As Double = 0
Public Dim SValue As Double = 0
Public Dim TValue As Double = 0
Public Function CalculateTotal(FirstValue as Double,SecondValue as Double,
ThirdValue as Double) as Double
ThisValue=ThisValue+FirstValue
SValue=Svalue+SecondValue
TValue=TValue+ThirdValue
TotalAmount=SValue/(ThisValue+TValue)*100
Return TotalAmount
End Function
在我的表情中:
=Code.CalculateTotal(Fields!N_ANSWERED.Value,Fields!SLA.Value,Fields!N_ABANDONED.Value)
我尝试防止除以零:
IIF((ThisValue+TValue)*100=0,1,(ThisValue+TValue)*100)
,但没有任何改变。
我期望零值。
答案 0 :(得分:0)
我只是添加一个If来检查您的TOTAL计算中的零分母。
Public Dim TotalAmount As Double = 0
Public Dim ThisValue As Double = 0
Public Dim SValue As Double = 0
Public Dim TValue As Double = 0
Public Function CalculateTotal(FirstValue as Double, SecondValue as Double, ThirdValue as Double) as Double
ThisValue = ThisValue + FirstValue
SValue = Svalue + SecondValue
TValue = TValue + ThirdValue
If ThisValue + TValue <> 0 Then TotalAmount = SValue / (ThisValue + TValue) * 100
Return TotalAmount
End Function
这样,如果您的总数为0,则不会执行总额计算。
您拥有的IIF是SSRS表达式语法,而不是VBA语法,这可能会导致其他错误。