Partial sum in SSRS 2008 R2 - reporting-services

I've a column with values for each month of the year.
Then in parameters of my report i would be able to set the month.
SSRS should return this column with values for each month of the year (like if there's no parameter) but the sum at the bottom of this column should return the sum of the value from the beginning of the year to the selected month.
Is it possible?

Yes. If I'm understanding correctly, you want something like the image below:
Assuming your MonthYear column is a DateTime and your month parameter is an Integer, you can use an expression like the following to conditionally sum the total based on the parameter value:
=Sum(IIf(Month(Fields!MonthYear.Value) <= Parameters!Month.Value, Fields!Value.Value, 0))

Related

SSRS - Average of periods with values

I'm having a problem trying to calculate the average of period totals for periods that have non-zero totals. The data that's being returned looks like this (simplified)
Data Being Returned
and I'm displaying it like this:
Format in SSRS
What I need is to calculate the sum of all the values (27,377) divided by the number of months with non-zero totals (5). So it would be 27,377/5 = 5,475.40.
I've tried CountDistinct combined with iif without success.
Thanks
In custom code you have to create a function that will calculate month count
Public Dim months As Integer
Public Function MonthCount (month As String, val As Decimal) As Decimal
If val <> 0 Then
months = months + 1
End If
Return month
End Function
The function takes as parameters the month sum and the month name.
If the month sum if is not equal to zero it increments the month counter.
Finally it return the month value in order to display it in the matrix
In the cell of the month name value, you call the custom function.
For your average, the expression should be like the one below
Sum(Fields!val.Value, "dataset") / Code.months
Use Sum with IIF expression something like
=Sum(IIF(Fields!TotalCost.Value > 0,1, 0))

SSRS Sum Values Based on Earliest Date

I'm trying to sum a net balance based on the earliest date in an SSRS report. In this case there are only 2 dates, but there can be more dates not more than 7 days.
Here's a sample of my data:
Here's what I'm trying to get with the earliest date of 10/26/15:
I've tried the following code, but not able to get this to work:
=Sum(IIf(DateDiff("d",Fields!SettleFullDate.Value,today())>=7
and DateDiff("d", Fields!SettleFullDate.Value, today())<7
and Fields!SETTLEBALANCE.Value>0), Fields!SETTLEBALANCE.Value, 0)
Update: I tried the code below and keep getting an error on the report. Could it be that I need to change the date field to an integer?
Thanks in advance for your help!
To compare the sum of values of two dates, the maximum and minimum in a set you can use the following equation
=Sum(iif(Fields!myDate.Value = Max(Fields!myDate.Value), Fields!myVal.Value, 0))
-Sum(iif(Fields!myDate.Value = MIN(Fields!myDate.Value), Fields!myVal.Value, 0))
This Sums all the values that match the maximum date in the dataset together, and sums all the values that match the minimum date in the dataset together, and takes one from the other.
It is irrespective of which dates you ask to be received, the above approach will work only against the records that you return to SSRS. So if you have a filter (WHERE clause) to return records between Date1 and Date2 this will still apply (Note - don't actually use 'Between' in the query)
Rather than using the maximum and minimum dates as listed here, you could also calculate a date similar to your original approach using
dateadd("d", -7, Fields!MySpecificDate.Value)
And insert that to the expression above.
Hopefully this is what you require - if not please let me know.

Create Single Colum Aggregat IN SSRS Matrix

We have a SSRS Matrix report with the following areas
RowGroup:MonthYear
ColumnGroups:Campaign,Year,Processed
Detail:Sum(Processed)
We have added a single column outside of the ColumnGroup for and expression that will show the increase/decrease of current year processed records over previous year processed records
The data is shaped like this:
lYear, MonthYear, Campaign, Processed
2014, JUL-10, XYZ, 120
2015, JUL-10, XYZ , 60
So the formula is basically CurrentYearProcessed/PreviousYearProcessed which in this example would yield 50%
So how can we specify this when writing the expression?
Just use IIF to filter for the year:
=SUM(IIF(FIELDS!lYear.VALUE = YEAR(GETDATE()), FIELDS!Processed.VALUE, 0) / SUM(IIF(FIELDS!lYear.VALUE = YEAR(GETDATE()) - 1, FIELDS!Processed.VALUE, 0)
This checks your lYear field to see if it's the same as the current year [ YEAR(GETDATE()) ] and sums the Processed field. Then it divides by the previous year's SUM using similar logic.

SUM of a SUM in SSRS 2008

I've this report
Here I make the first sum because I've grouped values from each month (months are "Gennaio", "Febbraio", "Marzo" etc etc.). These values are hidden, but anyway I get the sum and I display the sum for each month.
Then I should make the second sum that use values for each month and display the total for each category. Categories are "TOTALE LAVORI RESTAURO", "TOTALE LAVORI EDILE" etc.)
This is the final sum, where I sum values from each category.
Everything is working well, but now I have to add a "month" parameter to the report that returns sums until a selected month. This parameter changes the sum 1 with this expression:
=Sum(IIf(Fields!mese.Value <= Parameters!mese.Value, Fields!costi.Value, 0))
Now, how should I change expression in SUM2 and SUM3 to work with this parameter?
If I copy that code, ther returns #Error and as far as I know I can't use ReportItems sum.
So any suggestion?
SUM #1 could remain Sum(Fields!costi.Value) because you need to display every months.
i.e.: display GIUGNO even if Parameters!mese.Value = 4 (APRILE).
So you have only to change SUM #2 and #3 because TOTALE LAVORI RESTAURO and TOTALI must show only costi from GENNAIO to Parameters!mese.Value; i.e. if Parameters!mese.Value = 4 display only GENNAIO-APRILE even if we have details about GIUGNO.
The expression gave error because you have NULL value in Fields!costi.Value or Fields!mese.Value: convert this value to zero in your DataSet and you won't have problems.

SSRS report calculate field

I have a requirement of creating an ssrs report that needs to be showed in a matrix in this format
Dataset includes the following fields
year, month, values, account name
report format is something like this:
current month | month ( last year)| difference in %
account name
how do I calculate field for month of previous year? because SSRs does not have case or where logic inbuilt?
If you are doing this in your dataset you can do
DATEADD(YY,-1,COLUMN)
This will change your date a year back.
If you want to do this in the Report Side You can create a new column and create a calculated field and use:
=DateAdd(DateInterval.Year,-1,ColumnName)
Same Effect