SSRS 2008-除以零时出现错误消息

时间:2018-12-05 02:07:00

标签: reporting-services

在我的Texbox表达式中,除以零错误,我得到:

 =SUM ((Sum( IIF(Fields!Pay.Value = "G" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))  - Sum( IIF(Fields!Pay.Value = "N" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))  )  /   (Sum( IIF(Fields! Pay.Value = "G" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))) )

解决方案: 在菜单>报告>报告属性>代码中,我粘贴了以下代码:

Public Function Divider (ByVal Dividend As Double, ByVal Divisor As Double)
If IsNothing(Divisor) Or Divisor = 0
  Return 0
Else
  Return Dividend/Divisor
End If
End Function 

现在我在Texbox表达式中输入了此内容,并调用了创建的函数:

 =code.divider((Sum( IIF(Fields!Pay.Value = "G" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))  - Sum( IIF(Fields!Pay.Value = "N" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))  )  ,  (Sum( IIF(Fields!Pay.Value = "G" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))) )

除以零时,它仍然给我错误。我在这里做错了什么?我也错过了我在第一个表达式中得到的总和吗? 谢谢!

2 个答案:

答案 0 :(得分:0)

这对我有用:

= Sum(
    Code.Divider(
      Sum( 
        IIF(
          Fields!Pay.Value = "G" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0
        )
      ) - Sum(
        IIF(
          Fields!Pay.Value = "N" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0
        )
      ), Sum( 
        IIF(
          Fields! Pay.Value = "G" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0 
        )
      )
    )
  )

但是除法器之前的总Sum()无效,导致您已经对合计值进行了除法。

答案 1 :(得分:-1)

我对数据进行了修复,现在可以使用以前尝试的方法进行修复:

 =code.divider((Sum( IIF(Fields!Pay.Value = "G" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))  - Sum( IIF(Fields!Pay.Value = "N" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))  )  ,  (Sum( IIF(Fields!Pay.Value = "G" , Fields!EndBal.Value * 1, Fields!EndBal.Value * 0  ))) )

==>它在开始时不需要SUM。