我在报告中有这个表达式来计算比率:
=
SUM(Fields!PaidLosses.Value) /
Lookup(Fields!YearNum.Value & Fields!MonthNum.Value, Fields!YearStartRisk.Value & Fields!MonthNum.Value, Fields!EarnedPremium.Value, "EarnedAllCoverages")
当我选择数据不足的参数时,我得到了#Error和NaN。 NaN的结果是在“ - ”值上划分“ - ”。并且#Error的结果是在0值上划分“ - ”。
答案 0 :(得分:1)
尝试:
=SUM(Fields!PaidLosses.Value) /
IIF(
ISNOTHING(
Lookup(Fields!YearNum.Value & Fields!MonthNum.Value,
Fields!YearStartRisk.Value & Fields!MonthNum.Value,
Fields!EarnedPremium.Value, "EarnedAllCoverages")
) OR
Lookup(Fields!YearNum.Value & Fields!MonthNum.Value,
Fields!YearStartRisk.Value & Fields!MonthNum.Value,
Fields!EarnedPremium.Value, "EarnedAllCoverages") = 0,1,
Lookup(Fields!YearNum.Value & Fields!MonthNum.Value,
Fields!YearStartRisk.Value & Fields!MonthNum.Value,
Fields!EarnedPremium.Value, "EarnedAllCoverages")
)
这是因为你不能将任何数字除以零或nothing
(SSRS空值)
此外,您可以使用this great answer中提供的此自定义代码来安全地执行分割。
在Report
菜单/ Report Properties...
/ Code
标签
Public Function SafeDivide(ByVal Numerator As Decimal, ByVal Denominator As Decimal) As Decimal
If Denominator = 0 Then
Return 0
End If
Return (Numerator / Denominator)
End Function
然后在你的tablix中,只需用分子和分母作为参数调用函数:
=Code.SafeDivide(
SUM(Fields!PaidLosses.Value),
Lookup(
Fields!YearNum.Value & Fields!MonthNum.Value,
Fields!YearStartRisk.Value & Fields!MonthNum.Value,
Fields!EarnedPremium.Value, "EarnedAllCoverages"
)
)
如果有帮助,请告诉我。