SSRS报告组参数表达式导致除法错误

时间:2019-05-22 12:04:26

标签: reporting-services expression

我有一个报告,该报告使用表达式对组进行排序,但是当从参数中选择一个值时,它返回“分组'grp'的排序表达式包含错误:试图除以零。”

正在使用的表达式如下;

=Choose(Parameters!sort.Value,
Choose(Parameters!set.Value,Fields!IncomeOfficer.Value,Fields!    ManagementArea.Value,Fields!RentGroup.Value,Fields!Tenure.Value),
-Sum(Fields!RentCollected.Value,"grp"),
Sum(Fields!RentDue.Value,"grp"),
-Sum(Fields!RentCollected.Value,"grp")/Sum(Fields!RentDue.Value,"grp"))

任何想法修正都表示赞赏。

谢谢

2 个答案:

答案 0 :(得分:1)

在报表代码中添加一个函数以处理零除错误:

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

然后在表达式中调用函数:

code.Divider( Sum(Fields!RentCollected.Value,"grp")/Sum(Fields!RentDue.Value,"grp") )

答案 1 :(得分:0)

您如何简单地检查您的Sum(Fields!RentDue.Value,"grp")是否返回0或为null,如果不是,则不需要除以Sum(Fields!RentCollected.Value,"grp")/Sum(Fields!RentDue.Value,"grp") 否则就分裂。

我在下面更新了表达式。

=Choose(Parameters!sort.Value,
Choose(Parameters!set.Value,Fields!IncomeOfficer.Value,Fields!    ManagementArea.Value,Fields!RentGroup.Value,Fields!Tenure.Value),
-Sum(Fields!RentCollected.Value,"grp"),
Sum(Fields!RentDue.Value,"grp"),
-IIF(IsNothing(Sum(Fields!RentDue.Value,"grp")) or Sum(Fields!RentDue.Value,"grp")=0,Sum(Fields!RentCollected.Value,"grp"),  Sum(Fields!RentCollected.Value,"grp")/Sum(Fields!RentDue.Value,"grp")))