Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRS Sum Expression with Condition

I have a problem here, Have an SSRS report for Bank Transfer see attached Bank Transfer Per Bank

I would like to add a row expression which will Sum the total amount of the same bank, i.e, 03001 - Standard Chartered Bank Ltd BJL, 03002 - Standard Chartered Bank Ltd sk and 03002 - Standard Chartered Bank Base are all standard charters, i would like to get a total of all standard charters GMD figures. if need more clarification, please ask.

NB: Banks which are together e.g Standard charters above have a common field called BankAName. So the sum condition can be set to check if BankAName is the same.

like image 759
Kelvin Avatar asked Aug 30 '13 10:08

Kelvin


People also ask

How do I use IIF in SSRS expression?

Using IIF Function in SSRS We are going to add a new field to the report data set to determine if the Order Year is the Max or Current Year. As shown below, the dataset properties window is opened, and the Fields tab is selected. After clicking Add, at the bottom of the list a new field is added.

How do I sum in SSRS report?

In the tablix data region row group area, right-click a cell in the column group area for which you want totals, then point to Add Total, and click Before or After. A new column outside the current group is added to the data region, and then a default total is added for each numeric field in the column.

How do I add totals in report Builder?

Right-click the data region cell that contains the [LineTotal] expression, and select Add Total. Report Designer adds a row with a sum of the dollar amount for each order. Right-click the cell that contains the field [Qty] , and select Add Total.


2 Answers

You'll need something like this:

=Sum(IIf(Fields!BankAName.Value = "Standard Chartered Bank"
    , Fields!Amount.Value
    , Nothing)
  , "DataSet1")

This checks for a certain field (e.g. BankAName), and if it's a certain value that row's Amount value will be added to the total - this seems to be what you're after. You may have to modify for your field names/values.

By setting the Scope of the aggregate to the Dataset this will apply to all rows in the table; you can modify this as required.

like image 88
Ian Preston Avatar answered Sep 18 '22 12:09

Ian Preston


Modify your SQL query and add the new column showing the value you want

SELECT *, SUM(Amount) OVER(Partition By BankAName) AS BankANameSum
FROM myTable
Where Cond1 = Cond2

BankANameSum is the data field you can use in report design as it is. No need to apply any logic.

HTH.

like image 22
Anup Agrawal Avatar answered Sep 21 '22 12:09

Anup Agrawal