Reporting Services - 使用Matrix的多行动态总计

时间:2016-11-08 16:06:38

标签: c# vba reporting-services

我需要能够使用自定义代码来对不同的4级描述进行求和,并在4级描述中显示总计。这是一个矩阵报告。

报告

Report Image click here

enter image description here

Level 3      Level 4          2016-009    2016-010   2016-011
Arcadia      Personnel Rel     100          120        11
Arcadia      Other Expenses    100           10         1 
Arcadia      Shipping Rel      100           20         2

             Total             300          150        14

Chicago      Personnel Rel     1             30        10 
Chicago      Other Expenses    2             10        10
Chicago      Shipping Rel      100           10        10

             Total             103           50        30

Grand Total  Personnel Rel     101          150        21
             Other Expenses    102           20        11
             Shipping Rel      200           30        12

Final Total                    403          200        44                                

我开始使用这样的自定义代码,但我需要做一些类型的集合,用每个时期的正确总数存储描述。

在详细信息行中使用此表达式

=Code.AddTotal(Sum(Fields!Activity_Amt.Value), Field!Period_Nbr.Value, Field!Level4.Value)

此代码应跟踪第4级描述总计

自定义代码

 Public Shared detailTotal as New Collection

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

Dim subtotal as Double
Dim combineStr = period & "" &level4

if  not detailTotal.Contains(combineStr) Then
   detailTotal.Add(value, combineStr)
   subtotal = detailTotal.item(combineStr)
   return subtotal
end if

subtotal = detailTotal.item(combineStr) + value
detailTotal.remove(combineStr)
detailTotal.add(subtotal,combineStr)
return detailTotal.item(combineStr)
end function

2 个答案:

答案 0 :(得分:0)

即使您将描述存储在集合中,也无法使用它在Tablix中生成行。我认为你有两种选择。首先是在矩阵的单元格内嵌入一个Tablix来计算每个描述的总数;第二个选项(我推荐)是在任何组的范围之外添加三行,并在每个组中对描述进行硬编码。

enter image description here

注意Grand Total行和Final Total超出了Level 3和Level 4 Row Groups的范围,这就是诀窍。另请注意,每个描述都在单元格中进行了硬编码,因此您必须在数据集中为每个描述手动添加一行。

然后,为了计算每一行中的Grand Total(绿色),请使用如下的特定表达式。完全使用Personnel Rel

=SUM(IIF(Fields!Level_4.Value="Personnel Rel",Fields!Activity_Amt.Value,0))

Other Expenses使用:

=SUM(IIF(Fields!Level_4.Value="Other Expenses",Fields!Activity_Amt.Value,0))

Shipping Rel使用:

=SUM(IIF(Fields!Level_4.Value="Shipping Rel",Fields!Activity_Amt.Value,0))

Final Total行中,只需使用:

=SUM(Fields!Activity_Amt.Value)

它应该产生:

enter image description here

如果有帮助,请告诉我。

答案 1 :(得分:0)

我能够找到此链接以帮助解决我的问题。

https://sqlserverreportingservices.wordpress.com/2012/11/29/adding-a-group-to-a-matrix-to-create-subtotals/

我做了右击Add Group =>相邻下方的子总数

Click this link to review the report