Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何使用SUM和LOOKUP函数_Sql_Reporting Services_Sum_Lookup - Fatal编程技术网

Sql 如何使用SUM和LOOKUP函数

Sql 如何使用SUM和LOOKUP函数,sql,reporting-services,sum,lookup,Sql,Reporting Services,Sum,Lookup,在我的SSRS报告中,我有两个表:损失(表2)和赚取保费(表1),都来自不同的数据集。我需要根据每个月和每年的损失和赚取的保费计算比率。为此,我使用了LOOKUP函数,效果很好: SUM(Fields!PaidLosses.Value) / Lookup(Fields!AccidentYearNum.Value & Fields!AccidentMonthNum.Value, Fields!YearStartRisk.Value & Fields!MonthStartRisk.V

在我的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")

但是现在我需要计算总数。即每月和每年的总损失除以每月和每年的总赚取保费。 基于本文

我插入了这个自定义代码:

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"))

总数已累积到年度,因此不再需要月份。

表达式可能需要更改为:
=SUM(Fields!PaidLosses.Value)/code.SumLookup(lookUnder(Fields!acdentDreamum.Value,Fields!YearStartRisk.Value,Fields!EarnedPremium.Value,“EarnedAllCoverages”)
OMG!!!你让我开心了!!!!非常感谢你!!!你说得对,几个月不再是一组了。我现在觉得自己好笨:)很高兴你让它工作了!