1

我有一份报告应该按货币从 2 个数据集中读取值:

Dataset1: Production Total
Dataset2: Net Total

我试过使用:

Lookup(Fields!Currency_Type.Value, 
       Fields!Currency_Type1.Value,
       Fields!Gross_Premium_Amount.Value, 
       "DataSet2")

这仅返回数据集 2 中的第一笔金额。

我也尝试过 Lookupset 函数,但它没有对检索到的值求和。

任何帮助,将不胜感激。

4

2 回答 2

2

感谢杰米的回复。这就是我所做的并且效果很好:从 Report Properties--> Code ,编写以下函数:

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)
Next
If (ct = 0) Then return 0 else return suma 
End Function

然后就可以调用函数了:

code.SumLookup(LookupSet(Fields!Currency_Type.Value, Fields!Currency_Type1.Value,Fields!Gross_Premium_Amount.Value, "DataSet2"))
于 2012-11-02T07:09:46.443 回答
1

是的,Lookup 只会返回第一个匹配的值。想到三个选项:

  1. 更改您的查询,以便您只需要获取一个值:使用 a GROUP BYandSUM(...)将查询中的两行组合起来。如果您在其他地方使用此查询,请复制并更改它。
  2. 行有什么不同吗?比如一个是去年的,一个是今年的?如果是这样,请创建一个人工查找键并分别查找这两个值:

    =Lookup(Fields!Currency_Type.Value & ","
        & YEAR(DATEADD(DateInterval.Year,-1,today())), 
       Fields!Currency_Type1.Value & ","
        & Fields!Year.Value,
       Fields!Gross_Premium_Amount.Value, 
       "DataSet2")
    +
    Lookup(Fields!Currency_Type.Value & ","
       & YEAR(today()), 
      Fields!Currency_Type1.Value & ","
       & Fields!Year.Value,
      Fields!Gross_Premium_Amount.Value, 
      "DataSet2")
    
  3. 使用上述LookupSet功能。有了这个,您将获得一组值,然后需要将它们加在一起。最简单的方法是在报告中嵌入代码。将此函数添加到报告的代码中:

    Function AddList(ByVal items As Object()) As Double
       If items Is Nothing Then
         Return 0
       End If
       Dim Total as Double
       Total = 0
       For Each item As Object In items
          Total = Total + CDbl(item)
       Next
    
       Return Total
    End Function
    

    现在调用它:

    =Code.AddList(LookupSet(Fields!Currency_Type.Value, 
       Fields!Currency_Type1.Value,
       Fields!Gross_Premium_Amount.Value, 
       "DataSet2"))
    

(注意:此代码未经测试。我只是在 Stack Overflow 编辑窗口中编写它,我不是 VB 的粉丝。但它应该让您很好地了解该做什么。)

于 2012-11-01T14:38:54.830 回答