2011-12-01 100 views
0

在我的報告之一,我有以下字段的數據集:爲什麼列值始終是第一行中該列的值?

CategoryID ProductID PackType NumberOfItems 
1    1   1   2 
1    1   2   4 
1    1   3   12 
1    2   1   4 
1    2   2   8 
1    2   3   12 
2    1   1   3 
2    1   2   6 
... 

,我需要的輸出:

GroupHeaderA:

  • CategoryID
  • SUM(NumberOfItems where PackType = 1)
  • SUM(NumberOfItems where PackType = 3)
  • SUM((NumberOfItems where PackType = 2) - (NumberOfItems where PackType = 1))
  • SUM((NumberOfItems where PackType = 3) - (NumberOfItems where PackType = 2))

GroupDetailA:

  • ProductID
  • NumberOfItems where PackType = 1
  • NumberOfItems where PackType = 3
  • (NumberOfItems where PackType = 2) -(NumberOfItems where PackType = 1)
  • (NumberOfItems where PackType = 3) -(NumberOfItems where PackType = 2)

爲了實現此目的,我在ProductId的CategoryId和子組上創建了一個ParentGroup。在ProductID的細節部分,我已經放置了NumberOfItems和PackType。兒童組頭我把:

expression_1得到NumberOfItems的值,其中packtype爲1個

=IIF(Fields!PackType.Value = 1, NumberOfItems, 0) 

expression_2得到NumberOfItems的值,其中packtype是最大

=IIF(Fields!PackType.Value = Max(Fields!PackType.Value),NumberOfItems ,0) 

但表達沒有回覆正確。我發現Fields!PackType.Value總是爲1.爲什麼細節組的頁腳列總是顯示其第一行的值?

請告訴我,如果還有另一種方法可以實現這一點。

回答

0

除非您正在訪問詳細信息組中的字段,否則對不屬於分組標準的任何字段的引用都需要處於聚合中。

而不是=IIF(Fields!PackType.Value = 1, NumberOfItems, 0)嘗試:

=SUM(IIF(Fields!PackType.Value = 1, NumberOfItems, 0)) 

而不是=IIF(Fields!PackType.Value = Max(Fields!PackType.Value),NumberOfItems ,0)

=SUM(IIF(Fields!PackType.Value = Max(Fields!PackType.Value , "YourGroupNameHere"),NumberOfItems ,0)) 

這第二個,包含聚合將在SSRS之前2008R2不行的總和。我還沒有使用過這種表達方式,所以我甚至不確定它是否可以在R2中使用。如果這不起作用,那麼我會寫一些嵌入式代碼來獲得它。

相關問題