2016-11-08 44 views
-3

我需要使用自定義代碼才能在不同的級別4描述上進行總結,並在級別4描述中顯示總計。這是一個矩陣報告。Reporting Services - 動態總計,包含多條使用矩陣的行

這裏報告

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 
+0

那麼,你有一些代碼了嗎? – Hespen

+0

很抱歉忘了補充一點。 –

+0

@RobertThompson,3級和4級是矩陣中的組?你如何調用函數,它的期望行爲是什麼?在設計窗口中添加矩陣屏幕截圖。 –

回答

0

即使你的描述存儲在集合你不能用它來產生一個tablix中的行。我認爲你有兩個選擇。首先是創建在矩陣的單元格內嵌入一個tablix,以計算每個描述的總數;第二個選項(我推薦)是在任何組的作用域之外添加三行,並在每一個組中對該描述進行硬編碼。

enter image description here

注意總計行和最後總有3級和4級行組的範圍,那就是把戲。另請注意,每個描述都在單元格中進行硬編碼,因此您必須在數據集中爲每個描述手動添加一行。

然後爲了計算每行(綠色)中的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

讓我知道,如果這有助於。

+0

感謝Alejandro提供快速響應。我對你在下面的意見有點混淆。 **「在任何組的範圍之外添加三行,並在每個組中加上描述。」**。你是說創建3行並隱藏它們來進行計算。 –

+0

@RobertThompson,我的意思是你必須在Total行下面插入三個合計行來計算每個Level 4描述的總數。 –

+0

好的。我剛剛在5分鐘前發現了這個鏈接。這做到了這一點。 https://sqlserverreportingservices.wordpress.com/2012/11/29/adding-a-group-to-a-matrix-to-create-subtotals/ –

相關問題