简体   繁体   中英

Adding a simple calculated field in SSRS?

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

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
            )
        )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM