How can i Make This Type SSRS - reporting-services

I have a table in data base which has column MonthNo ,Year ,MonthValue ,AvgYTD and it has values in
1 ROW... 1 , 2010 , 2.3 , 4.0 AND
2 ROW... 2, 2010, 3.3 ,5.0 AND
3 ROW.. 3, 2010, 3.3, 7.9
AND I want output in my SSRS.....
WHEN I SELECT MONTH MARCH USING PARAMETER THEN OUTPUT WILL BE....A TABLE AND IT HAS COLUMN
JAN , FEB , MARCH , AVGYTD and values in row are ..
2.3 ,3.3, 4.3, 7.9
Updates
i am using sql server 2005 and 7.9 is th AvgYTD Value comes from table for selected month march....
i want ...if i select month march then output will be show month value of jan,feb and march and AvgYTD value for only selected month..
thanks,

Use a matrix, and if SQL 2005, use the InScope function to be able to tell if you're in the SubTotal column. In SQL 2008 you can just put a column in there for the appropriate YTD value.
Edit, to explain it more thoroughly:
Put a Matrix in the report. Use a column group on Year, MonthNo. By default that group will be called matrix1_ColumnGroup1 (or something like that - go to Edit Group to set it to something better). Put a row group on whatever causes a second row to appear.
In the Cell part of the Matrix, use an expression like:
=IIF(InScope("matrix1_ColumnGroup1"), First(Fields!MonthValue.Value), Last(Fields!AvgYTD.Value))

Related

How to tie the column visibility expression in SSRS to current year and current month?

I have an SSRS report that has all 12 months as columns and one more column called "Year". I already have a condition set that takes the current month of the report run date and displays only the months that have passed. For example, the expression looks like this for March =IIF(Month(today()) < 3, True, False).
Now I have to tie this to the Year column as well. The condition is- if the Year column has years prior to the current year, the condition above should not apply. So, if I am running 2020 data today, all 12 month columns should appear. If I am running 2021 data, I should only see the January column. Can some one please help me with this? And yes, there will only be one year in the "Year" column. The data will never have more than one year.
Thank you.
Edit 1:
If the report is run for 2020, the data should look like this on the report.
If it is run for 2021, only the YEAR and JANUARY columns should appear. Starting February of this year, YEAR, JANUARY, AND FEBRUARY should appear.
As your dataset is not normalised, you will have to set the column visibility on each column as you are doing already.
Try using the following expression. (using March as an exmaple)
=(Month(today()) < 3 AND MAX(Fields!Year.Value, "DataSet1") = YEAR(Today())
Note: The "DataSet1" reference is the name of your dataset. It is case sensitive and must be enclosed in quotes as shown above.
There is no need for the IIF() expression as the above will return true if either condition is met.
Alternative
If your data was normalised (you may be able to edit your dataset query) and looked something like this...
Year Month Amount
2021 1 10
2021 2 15
Then you could simply use a matrix instead of a table, and have a column group by month. There would be no need to set visibility on anything as the data simply is not there so no column would be rendered for the months with no data.

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.

Graph in SSRS only shows a couple of week's data

I'm making a graph in SSRS which will highlight the sales for each week from a specific week, and from 52 week up to that date.
For this I have created the following data set in SSRS:
WITH SET LAST52WEEKS AS
{
STRTOMEMBER("[Dim Date].[Week].&[2017]&[1]&[1]&[4]").Lag(52):
STRTOMEMBER("[Dim Date].[Week].&[2017]&[1]&[1]&[4]")
}
Select {[Measures].[Quantity]} ON 0,
{Last52Weeks} ON 1
FROM (
Select {
[Dim Store2].[Store Key].&[1024]
} on columns
from [DSV_FactStoreSales 1]
)
which works as intended, and have an output for week 13 through 4 with each week having a weekly sales Quantity>400 (except for one week with Quantity (null).
However, when I add this data as the Y-axis in a graph in SSRS along with Weeks attribute as the X-axis, only four rows are returned. The rows returned are for the weeks
1,19,3,40
All other values are blank in the graph. Does anyone have any idea as to why this may occur?
Regards,
Cenderze
EDIT updated x-axis from using Interval value = 1
When I changed the Interval value under Horizontal Axis Properties I now get the following values for the x-axis:
1, 13, 14,[...],19, 2, 20, 21, 22, 23, [...], 29, 3, 30, 31, 32,[...],39, 4, 41, 42,[...], 53
where I have bolded the results which seem odd. Im guessing these values are the quarters? I am however using Weeks as my Grouping variable.
EDIT
Following Mike Honey I figured that:
WITH SET LAST52WEEKS AS
{STRTOMEMBER("[Dim Date].[Date].&[1]&[2017-01-29]").Parent.Lag(52)
:
STRTOMEMBER("[Dim Date].[Date].&[1]&[2017-01-29]").parent}
Select {[Measures].[Quantity]} ON 0,
{Last52Weeks} ON 1
FROM (
Select {
[Dim Store2].[Store Key].&[1024]
} on columns
from [DSV_FactStoreSales 1])
ought to work, but it simply returned that Quantity was (null). Why isn't this equivalent to the other Query I wrote, but based off of Date rather than week?
EDIT
I also noted that the graph I am creating has week 52 to the utmost right, whereas it is supposed to have week 4 at the utmost right.
EDIT
EDIT
Edited the Query to become:
WITH SET LAST52WEEKS AS
{STRTOMEMBER("[Dim Date].[Hierarchy].&[2017 W4]").Lag(52):STRTOMEMBER("[Dim Date].[Hierarchy].&[2017 W4]")}
Select {[Measures].[Quantity]} ON 0,
{(Last52Weeks,[Dim Store2].[Store Name].Allmembers)} ON 1
from [DSV_FactStoreSales 1]
where Hierarchy is an Attribute Hierarchy with the values 2010 W1,...., 2018 W52.
But this yields me an output:
2016 W40 Store1 300
2016 W40 Store2 400
...
2017 W39 Store1 400
where I would expect the output to be:
2016 W4 Store1 300
2016 W4 Store2 400
...
2017 W4 Store1 400
Any ideas? It is just an hierarchy with one attribute, Week Name (I've tried the Query with both using [Dim Date].[Hierarchy].[Week Name].&[2017 W4] and [Dim date].[Hierarchy].&[2017 W4], both with the same output.
EDIT (very close now!)
There are two issues I can see with your current chart. One is that your week numbers are being treated as text, which is why the ordering has sequences like 19, 2, 20. The other is that it isn't distinguishing where the week numbers for one year ends and another year starts.
I'm not familiar with mdx. I'm hoping you're able to make a simple dataset that is purely a list of sales with dates. For my solution, I used an Oracle query like:
SELECT date SALEDATE, ID FROM sales
WHERE date BETWEEN '28-MAR-2016' AND '28-JAN-2017'
With a new chart, use [Count(ID)] for the values. It then needs two category groups, first one for the year and then one for the week number. You can use expressions to get these from a date field. For the first category group, set Group on: and Label as
=DatePart(DateInterval.Year, Fields!SALEDATE.Value)
and for the second, set Group on: and Label as
=DatePart(DateInterval.WeekOfYear, Fields!SALEDATE.Value)
To then hide the columns with under 400 sales, right-click the second category group (the weeks one) and add a filter: [Count(ID)] (integer) > 400.
Even if your dataset is different from the raw data approach I'm using, hopefully this will steer you in the right direction.
Right click on the x-axis and choose "Horizontal Axis Properties". Under Axis Options change the Interval value from Auto to 1.

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

SSRS 2008 Dataset Filtering - SUM / Break down by month

I have a dataset that is going to get passed to an SSRS report that looks like this:
CODE TEXT COUNT MONTH
100 ABC 20 January
100 ABC 10 February
200 DEF 15 January
200 DEF 15 February
300 GHI 0 x
400 JKL 10 January
This 'x' indicates there is no data for that code/text for the current year, however, I still need it to display. In SSRS I want to have a column to display for the current month (February) and a column to display for year to date:
CODE TEXT MONTH_TO_DATE YEAR_TO_DATE
100 ABC 10 30 [20 + 10]
200 DEF 15 30 [15 + 15]
300 GHI 0 0 [0]
400 JKL 0 10 [0 + 10]
Is this possible in SSRS 2008?
This is going to have to be done in SQL so it would be easier to adjust the SQL if you posted what you have already, rather than the data resulting from that SQL.
Anyway, we have to find a way to know it is the current month and display it, which we can do with the SQL CASE statement. Maybe you have a date field you can query which might be cleaner than below, but I'll just run with the data as you have provided (that is, we just have a month name which we compare to the current month using the DATENAME and GETDATE SQL functions - obviously this doesn't work if you have multiple years of data as every February will be aggregated into the current month, but you get the idea for what to do):
SELECT [CODE], [TEXT],
SUM(CASE WHEN [MONTH] = DateName(month, GetDate()) THEN [COUNT] END) AS CurrentMonth,
SUM([COUNT]) AS YearToDate
FROM MyTable
GROUP BY [CODE], [TEXT]
ORDER BY [CODE], [TEXT]
Now, in your comment on Vlad's answer you say you can't do a SUM(COUNT(fieldname)) which you can actually do if you use nested queries, like so:
SELECT [CODE], [TEXT], SUM([COUNT]) AS Total
FROM ( -- This is a nested query
SELECT [CODE], [TEXT], COUNT(somefield) AS [COUNT]
FROM MyTable
)
GROUP BY [CODE], [TEXT]
ORDER BY [CODE], [TEXT]
If you want to display x for the zero values then use the following Format for the YearToDate cell:
#,##0;-#,##0;x
This can be done in either SQL or SSRS - doing it in SQL (as described by Chris Latta) should be simpler and more efficient, but if that option is not available, here is how to do it in SSRS:
Add a 4-column table to the report, with the appropriate dataset.
Add a group (including group footer) on your CODE and TEXT columns to the table.
Add your CODE and TEXT values to the group footer.
Delete (or hide) the Details section row on your report.
Enter the following expression into the appropriate cell in the group footer row for the year-to-date column:
=Sum(Fields!COUNT.Value)
Enter the following expression into the appropriate cell in the group footer row for the month-to-date column:
=Sum(iif(MonthName(DatePart("m",Now()))=Fields!MONTH.Value,Fields!COUNT.Value,0))
I think you should return this from the sql select/stored procedure. You should use a LEFT JOIN i think for those 0 results