Calculate percentage in ssrs report - reporting-services

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.

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 Expression: First(Value) but only if Value2 = X

Sorry, not sure how much sense my title makes.
Basically...I have a report and the dataset (Named DataSet1) returns data something sort of like this.
Quarter MonthID Month Value1 Value2 QtrAvgValue1 QtrAvgValue2
Q-1 1 Mar 2017 12 28% 12.3 24.0%
Q-1 2 Feb 2017 15 12% 12.3 24.0%
Q-1 3 Jan 2017 10 32% 12.3 24.0%
Q-2 4 Dec 2016 18 25% 17.3 24.3%
Q-2 5 Nov 2016 14 18% 17.3 24.3%
Q-2 6 Oct 2016 20 30% 17.3 24.3%
The last two columns are just the averages for that rows entire quarter. The [Quarter] column is read like -1 means last quarter, -2 means the quarter before. The MonthID column is just an auto increment that goes up for every month older going back. So the most recent month would be 1, the next month older would be 2.
I need an expression that will let me say something like this:
WHEN Quarter = Q-1 THEN return QtrAvgValue1; Which would return 12.3;
I would also need an expression that could say:
WHEN MonthID = 1 THEN return Value1; Which would return 12;
Is this possible? I would hate to have to pivot my dataset to be a crap ton of columns with ridiculous column names
NOTE: I have tried using IIF with SUM/AVG and it works with numerical values as a sort of hack...but I cannot think of a way to handle string values.
UPDATE: I figured it out, using the Lookup and LookupSet functions in SSRS, which I have never used before.
Example:
=LookupSet("Q-1", Fields!Quarter.Value, Fields!QtrAvgValue1.Value, "DataSet1")(0)
LookupSet is normally used for One to Many relationships, but it will still work in one to one relationships as well.
This expression basically says to look up all rows that have the Quarter of "Q-1" and return the column [QtrAvgValue1].
The Lookup set function puts data into an array, so the "(0)" at the end indicates to use the first value in the array...essentially the same thing as the "First()" function.

SSRS 2008 R2 Subtracting current row from previous row where data is summed

I am fairly new to SSRS 2008 R2. Trying to convert my reports from Crystal. Thought this would be a simple task but this ended up being a pain. I have a table that is grouped by Year then Week_Number so the table looks this when run: (I am trying to create the total row)
Week1 Week2 Week3 Week4
2013 1 2 5 4
2014 0 3 2 6
Total -1 1 -3 2
There is a row group called Year and column group called Week_Number. I have one expression in the total column Sum(Fields!TotalProdWTD.Value).
I added a group footer to try create the total row. I am able to sum the column works fine, I can get the value of the last row by doing this ReportItems!txtTotalProd.Value. But when I try to use
=Previous(ReportItems!txtTotalProd.Value)
I get the aggregate functions can be used only on report items contained in page headers and footers message. I believe I have to add a reference to the group to make the previous function work, just not sure how to do that.
With your report table
Insert new row outside group below
And use your command:
Sum(Fields!TotalProdWTD.Value) to expression textbox
I found what I was looking for here. At the bottom of the article:
http://msdn.microsoft.com/en-us/library/ms157328.aspx

Creating waterfall graph using SSRS Report Builder 3.0?

I'm trying to create this Waterfall graph using SSRS Report Builder but still haven't figured it out:
Let's say I have this data :
In the start of 2013, I have a total of 125
Now in 2013, each quarter has their own amount that eventually will sum up for the total amount in start of 2014 (which is 275).
ID || Desc || Amount
1 || Q1 || 80
2 || Q2 || -60
3 || Q3 || -40
4 || Q4 || 175
Notice that the first and last bar are for the start of 2013 and the start of following year (2014). And also if the amount is negative, the bar will go down vice versa.
Can it be done with SSRS Report Builder?
I dont think this can be achieved in Report Builder alone. I would try to create two series (one for the years, one for the quarters) and assign one series to the secondary axis.
The problem with just Report Builder is you need to set the Vertical Axis Min and Max for the Quarters series so that it appears as if the 0 value for Quarters = the 2013 value. In your example the Min Value for the Quarters Vertical Axis should be -125, and the Max should be 150.
You might be able to come up with an SSRS Expression to derive those Min and Max values, but I doubt it. I would try to pre-calculate those Min and Max values e.g. in SQL with a CTE.

SSRS 2008 month number not displayed in order

I have a SSRS 2008 report that generated columns of the months along with other data based on year halves. I have the tablix column group and sort set for [Mon] and the first half of the year generated just fine but when I run the report for the second half it does not display in order :
MonthNumber 10 11 12 7 8 9
MonthName October Movember December July August September
The SQL code that is used generated the following rows which appear in order of month number.
Mon
7
8
9
10
11
12
I would say that Mon is being treated as a string value, for whatever reason, i.e. from the query or in the dataset definition, as you can see that in your example the columns are being sorted as strings, i.e. 10 will be before 7 when sorted as text and not numeric values.
You have two options:
First is to sort by an expression like: =CInt(Fields!Mon.Value), i.e. explicitly sorting as an integer, which solve the issue if Mon is being treated as text.
The other option is to make sure that Mon is being treated as an integer at the dataset level - either way should be fine.