Reputation: 2012
I am trying to create a report in SSRS. I have created a simple table report now I need to add a calculated field in that table. Below is that two fields which I need to use to create the calculated field.
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
I need to put a if condition that is:
sum of values that has type Invoice - Sum of values that has type Credit Memo
I have created 2 calculated fields for that, first is:
SumOfInvoice==iif(Fields!new_documenttypeValue.Value="Invoice",(Sum(Fields!invoicedetail1_extendedamountValue.Value)),0)
Second is:
SumOfCreditMemo==iif(Fields!new_documenttypeValue.Value="Credit Memo",(Sum(Fields!invoicedetail1_extendedamountValue.Value)),0)
and then I added a column to the table and write an expression that :
=Sum(Fields!SumOfInvoice.Value)-Sum(Fields!SumOfCreditMemo.Value)
But It is giving me this error:
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.
Can someone please help me with that??
Thanks
Upvotes: 0
Views: 8845
Reputation: 10066
You can nest IIF inside SUM
Sum Of Invoice
=SUM(
Iif(Fields!new_documenttypeValue.Value="Invoice",Fields!invoicedetail1_extendedamountValue.Value,0)
)
The same for credit memos
=SUM(
Iif(Fields!new_documenttypeValue.Value="Credit Memo",Fields!invoicedetail1_extendedamountValue.Value,0)
)
Invoice - credit expression
= SUM(
Switch(
Fields!new_documenttypeValue.Value="Invoice", Fields!invoicedetail1_extendedamountValue.Value,
Fields!new_documenttypeValue.Value="Credit Memo",-Fields!invoicedetail1_extendedamountValue.Value,
True, 0
)
)
Or a more simple alternative since you only have invoice and credit memos could be
=SUM(
IIF(
Fields!new_documenttypeValue.Value="Credit Memo",
-Fields!invoicedetail1_extendedamountValue.Value,
Fields!invoicedetail1_extendedamountValue.Value
)
)
Upvotes: -1