SSRS - Get value from different row - reporting-services

I have a row group that returns monthly totals. For example I have column January, February. There are 3 rows.
Description January February
Total 1000 0
Spending 10 0
Percentage 10% [Blank]
In the column february, when the Total is zero, the percentage should be set to nothing/blank. I have tried to use the expression below:
=IIf((Fields!Description.Value = "Percentage" AND
Previous(Fields!February.Value)=0),nothing,Sum(Fields!February.Value))
But I get an error - The value expression for the text box 'textbox51' has a scope parameter that is not valid for an aggregate function...
My question is, how do we check if the value in the cell 2 rows before is 0 and sent the value in the
current cell (percentage) to nothing?

Related

Populate a cell in SSRS report by testing value conditions from other column value

Populate a cell in SSRS report by testing value conditions from other column values
I have 3 columns (category, Month, Amount) in my dataset, with values similar to these below:
Category Month Amount
A Jan 20
A Feb 25
A Mar 10
R Jan 15
R Feb 50
R Mar 55
On the report I need:
Jan Feb Mar
A 20 25 10
R 15 50 55
I have tried placing this expression in each group row column, for example, in the "Feb" column it would be:
=IIF(Fields!Category.Value = "A" and Fields!Month.Value = "Feb", Fields!Amount.Value, 13)
Using IIF, which does not short-circuit, is not evaluating the conditions properly. The "Month" value being a string, it displays always the first row found for the conditions, in this case it would display value 20, instead of 25. If I change the "Month" value to int, it displays the false(13);
How can I populate my cell correctly, using IIF or something other way?
Any help on this is deeply appreciated.
You don't need to do anything like that.
Just use a matrix instead of a table.
Add the matrix to the report, you'll see three placeholder names, (from memory) something like Rows, Column and Data. Drag your Category field to the rows cell, your month field to the columns cell and your Amount field to the data cell. That's it....
The only problem you will have is the columns would be ordered alphabetically by default. It would be better to have the Month number in your dataset too so you can order by that. You set the column order by right-clicking the column group name in the row/column group panel which is under your main report design area.

SSRS Grouped total sum issue

I'm creating a SSRS report that shows projected sales for the next 12 months, grouped by ProductID. While the detail cells are showing correctly, the group sums for each month are displaying all sales for the 12 months rather than just the related month.
For example, here are all the table values for a single Product:
ProductID EstimatedDate ProjSales
123A Oct 10/2017 100
123A Nov 15/2017 100
123A Dec 01/2017 100
123A Dec 31/2017 100
However, this is what the report is currently showing for this Product:
Product EstimatedDate Oct 2017 Nov 2017 Dec 2017
123A Oct 10/2017 100 0 0
Nov 15/2017 0 100 0
Dec 01/2017 0 0 100
Dec 31/2017 0 0 100
Total 400 400 400
As seen above, the detailed cells calculate perfectly as each record in the detail section displays a Projected sales value if the Year/Month matches, otherwise it displays 0. Unfortunately, the final row with the "Total" amounts is incorrect as the monthly cells are showing the total of projected sales for all months rather than just the month in question.
Here are my report expressions for December 2017:
Detail Cell:
=IIF(Year(Fields!EstimatedDate.Value) = 2017 AND Month(Fields!EstimatedDate.Value) = 12, Fields!ProjSales.Value, 0)
Grouped Cell
=IIF(Year(Fields!EstimatedDate.Value) = 2017 AND Month(Fields!EstimatedDate.Value) = 12, SUM(Fields!ProjSales.Value), 0)
Any idea how I can change the grouped expression to retrieve the projected sales for each month?
Edit : format code
Use a Matrix.
Add a column group and group by year then month.
Then simply have ProjSales in the detail row group and SUM(ProjSales) in the Group total. There is no need to use expressions to calculate the values.
The column group captions will have to be expressions in order to pull out the month and year from the EstimateDate column. If you have the stored dates in a more conventional format YYYYMMDD etc then it would be easier as I'm not sure any DATE functions will recognise the format you show above.
If you need a more detailed answer let me know. I'm not able to do anything more at the moment.

SSRS Get Last Row including zero values

I need help on the SSRS Last Function.
Sample for the report that I build.
I need to get the value of the last row using LAST Function but after I use Last Function the value I get is 20 it disregards the 0 value for ID 4 which is the last record
ID VALUE
1 10
2 0
3 20
4 0
Last 20
My guess would be that SSRS is giving you the correct value based on the scope which you're giving it. If you're not specifying a scope, then it will look at the lowest-level group it can find and return the last value in that group. Chances are, the data is being sorted at some point. Sorting in SSRS can occur in the SQL query, in the Tablix properties, or in the group properties.
If you have any sorting anywhere in the query or tablix or group that is sorting ascending, then depending on the scope specified for the Last() function, you would return 20.

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.

Calculate percentage in ssrs report

I have one ssrs report having matrix table which looks like this
YEAR A1 B1 Total percentage
2012 23 11 34
2013 12 12 24
2014 32 43 75
here i need to find percentage using below formula in ssrs expression
(Total of current year-Total of previous year)/(Total of previous year)*100
[for ex take 2012 - (Total for 2012-Total for 2011)/(Total for 2011)*100
The easiest way is to add a column to your data set that had the previous year total. Then you would right click the Percentage field and create an expression like the one above you want to calculate.
Expression Examples
One way easy way would be to use the Function previous, in SSRS this function returns the previous row item. Calculating the percentage would then be something like:
((Previous(Count(Fields!Day.Value))-ReportItems!Textbox22.Value) / ReportItems!Textbox22.Value )
Note: Textbox22.Value would be the base item/count you are comparing as a percentage.