Reporting Services使用自定义代码问题计算子总计

时间:2016-11-03 19:41:21

标签: c# vb.net reporting-services

我正在使用自定义代码来计算小计。小计总数正在向下运行。

如果我运行报告一段时间,下面的自定义代码工作正常。

自定义代码

Public Shared Dim SortCodeTotal as Decimal

Public Shared Function Initialize()
    SortCodeTotal = 0
End Function

Public Function AddTotal(ByVal b as Decimal) as Decimal
   SortCodeTotal  = SortCodeTotal + b
   return b
End Function

Public Function DisplayTotal(ByVal b as Decimal) as Decimal
    Dim ret as Decimal = 0
    ret = SortCodeTotal + b
    SortCodeTotal = ret
    return ret
End Function

明细专栏包含此表达式

=Code.AddTotal(Sum(Fields!Activity_Amt.Value))

摘要总计包含此表达式

=Code.DisplayTotal(0)

报告使用矩阵。运行超过1个周期时自定义代码不正确。如何更改自定义代码以在矩阵中的所有句点上工作。

小计的工作方式类似于总计。

实施例

Detail 1     $50
Detail 1     $50
Sub Total   **$100**

Detail 2     $40
Detail 2     $40
Sub Total   **$180**

Detail 3     -$50
Detail 3     $50
Sub Total   **$180**

Detail 4    $20
Detail 4    $50
Sub Total   **$250**

总计发生在上一个子总数 + 下一个明细行

Click this to see how the report looks

Click this to review the report

1 个答案:

答案 0 :(得分:0)

您的问题似乎与SSRS处理矩阵的方式有关。在传递到下一行之前,会对每一行进行评估,因此您需要水平计算累计总数,而每列需要垂直运行总计。

以下自定义函数使用Collection来存储每行的每个句点的总和。

Public Shared dict As New Collection

Public Function AddTotal(ByVal value as Double, ByVal period As String) As Object

    Dim subtotal As Double

    If not dict.Contains(period) Then
        dict.Add(value, period)
        subtotal = dict.Item(period)  
        Return subtotal
    End If
    subtotal = dict.Item(period) + value
    dict.Remove(period)
    dict.Add(subtotal,period)
    Return dict.Item(period)

End Function

要调用此函数,请使用:

=Code.AddTotal(sum(Fields!Activity_Amount.Value),Cstr(Fields!Period.Value))

我认为不需要额外的功能,因为只要您在正确的范围内,句点组内,详细信息组外部以及Sort Code内部使用它,它就会返回每个评估中的累计总数。基。

enter image description here

它产生:

enter image description here

在我的数据集Period字段中,值为1和2