在我的SSRS报告中,我有两个表:损失(表2)和赢得的保费(表1),两者都来自不同的数据集。我需要根据每个月和每年的损失和获得的保费计算比率。为此,我使用了LOOKUP功能,它工作正常:
SUM(Fields!PaidLosses.Value) / Lookup(Fields!AccidentYearNum.Value & Fields!AccidentMonthNum.Value, Fields!YearStartRisk.Value & Fields!MonthStartRisk.Value, Fields!EarnedPremium.Value, "EarnedAllCoverages")
但现在我需要计算TOTALS
。这是每个月和每年的总损失除以每个月和每年的总保费。
基于这篇文章
http://www.sqlservercentral.com/blogs/salvoz-sql/2013/05/27/sum-result-of-ssrs-lookupset-function/
我插入了这个客户代码:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next
If (ct = 0) Then return 0 else return suma
End Function
现在我正在使用这个表达式:
=SUM(Fields!PaidLosses.Value) / Code.SumLookup(LookupSet(Fields!AccidentYearNum.Value & Fields!AccidentMonthNum.Value, Fields!YearStartRisk.Value & Fields!MonthStartRisk.Value, Fields!EarnedPremium.Value, "EarnedAllCoverages"))
答案 0 :(得分:1)
Answer: The expression for the total in the 3rd matrix needs some adjustment.
=SUM(Fields!PaidLosses.Value) / Code.SumLookup(LookupSet(Fields!AccidentYearNum.Value, Fields!YearStartRisk.Value, Fields!EarnedPremium.Value, "EarnedAllCoverages"))
The total is rolling up to the year, so the months are no longer needed.