除以SSRS为零

时间:2015-10-22 14:21:04

标签: reporting-services reportbuilder

我需要帮助将逻辑添加到以下代码中以处理除以零

=iif(Fields!COVERAGE.value = 0, Sum(Fields!CalculatedTotalIncidents.Value) / (ReportItems!CalculatedUnitsSold1.value), Sum(Fields!CalculatedTotalIncidents.Value) / Sum(Fields!CalculatedUnitsSold.Value))

2 个答案:

答案 0 :(得分:1)

如果您在报告的自定义代码

中实现一个功能,那应该非常简单
function div (a as integer, b as integer) as decimal
 if (a > 0 ) then
   div = a/b
 else
   div = 0
 end if
end function

然后在报告中调用此函数。您还可以根据您的特定业务规则扩展此功能。

希望这有帮助。

答案 1 :(得分:0)

试试这个:

=iif(Fields!COVERAGE.value = 0,
Sum(Fields!CalculatedTotalIncidents.Value)/
   iif((ReportItems!CalculatedUnitsSold1.value)<>0,
   (ReportItems!CalculatedUnitsSold1.value),1),
Sum(Fields!CalculatedTotalIncidents.Value) / 
   iif(Sum(Fields!CalculatedUnitsSold.Value)<>0,
Sum(Fields!CalculatedUnitsSold.Value),1))