0

我正在嘗試在SSRS中創建報告。我已經創建了一個簡單的表格報告,現在我需要在該表格中添加一個計算字段。下面是我需要用來創建計算字段的兩個字段。在SSRS中添加一個簡單的計算字段?

type   value 
Credit Memo 3463 
Invoice  2623 
Invoice  3105 
Invoice  3664 
Invoice  2040 
Credit Memo 2929 
Credit Memo 2424 
Invoice  2549 
Invoice  2129 
Credit Memo 2957 

我需要把一個if條件是:

和值的有發票類型 - 值的總和有類型的信用憑證

我已經建立2個計算字段即,第一個是:

SumOfInvoice==iif(Fields!new_documenttypeValue.Value="Invoice",(Sum(Fields!invoicedetail1_extendedamountValue.Value)),0) 

二是:

SumOfCreditMemo==iif(Fields!new_documenttypeValue.Value="Credit Memo",(Sum(Fields!invoicedetail1_extendedamountValue.Value)),0) 

,然後我添加了一個列到表中寫的表達式:

=Sum(Fields!SumOfInvoice.Value)-Sum(Fields!SumOfCreditMemo.Value) 

但它給我這個錯誤:

The expression used for the calculated filed SumOfInvoice includes an aggregate, RowNumber, Running Value, Previous or lookup function. Aggregate, RowNumber, RunningValue, Previous and lookup functions cannot be used in calculated field expressions.

是否有人可以幫我嗎? ?

感謝

+0

你不能把這些表達式的數據集計算字段,但你可以把它們放到一個細胞的表他們應該工作得很好。爲了澄清表達式應該以'= iif'開始,你不需要在那裏輸入一個名字。 – StevenWhite

+0

我同意,雖然表達式有點笨拙,但您應該使用它們而不是嘗試創建臨時變量。另外請注意,當你計算最終值時,你已經將創建臨時變量時的值相加,所以每個臨時變量周圍的Sum()對我來說似乎都是多餘的... – Aron

+0

我正在嘗試這個表達式直接現在它顯示#錯誤?? – Mogli

回答

0

可以嵌套IIF內部SUM

總和發票

=SUM(
Iif(Fields!new_documenttypeValue.Value="Invoice",Fields!invoicedetail1_extendedamountValue.Value,0) 
) 

同爲貸項通知單

=SUM( 
Iif(Fields!new_documenttypeValue.Value="Credit Memo",Fields!invoicedetail1_extendedamountValue.Value,0) 
) 

發票 - 信用表達

= SUM(
Switch(
Fields!new_documenttypeValue.Value="Invoice", Fields!invoicedetail1_extendedamountValue.Value, 
Fields!new_documenttypeValue.Value="Credit Memo",-Fields!invoicedetail1_extendedamountValue.Value, 
True, 0 
) 
) 

或者更簡單的選擇,因爲你只有發票和貸記憑證可能是

=SUM( 
     IIF(
     Fields!new_documenttypeValue.Value="Credit Memo", 
     -Fields!invoicedetail1_extendedamountValue.Value, 
     Fields!invoicedetail1_extendedamountValue.Value 
      ) 
     )