如何将 SUM 与 LOOKUP 函数一起使用
How to use SUM along with LOOKUP function
在我的 SSRS 报告中,我有两个表:损失 (Table2) 和已赚保费 (Table 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"))
但出于某种原因,这并没有给我正确的答案。
我在这里错过了什么?
答:第三个矩阵的合计表达式需要做一些调整。
=SUM(Fields!PaidLosses.Value) / Code.SumLookup(LookupSet(Fields!AccidentYearNum.Value, Fields!YearStartRisk.Value, Fields!EarnedPremium.Value, "EarnedAllCoverages"))
总计已累计到年,因此不再需要月份。
在我的 SSRS 报告中,我有两个表:损失 (Table2) 和已赚保费 (Table 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"))
但出于某种原因,这并没有给我正确的答案。
答:第三个矩阵的合计表达式需要做一些调整。
=SUM(Fields!PaidLosses.Value) / Code.SumLookup(LookupSet(Fields!AccidentYearNum.Value, Fields!YearStartRisk.Value, Fields!EarnedPremium.Value, "EarnedAllCoverages"))
总计已累计到年,因此不再需要月份。