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.
Related
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.
I have to fetch data from table MonthWise. I have created a PARAMETER - #SELECTMONTH and kept this parameter as static. I had put specific value in available values i.e.
for eg. Label - Jan Value - Jan
Label - Feb Value - Feb and so on
I have used this parameter in query. i.e.
Select Month FROM Table WHERE Month in (#SelectMonth)
Union all
Select 'Jan-Feb' as Month FROM Table Where Month in ('Jan-19','Feb-19')
Union all
Select 'Jan-Feb-Mar' as Month FROM Table Where Month in ('Jan-19','Feb-19','Mar-19')
Under DataSet Properties > Parameters > Add > Parameter Name - #SelectMonth and Parameter Value - [#SelectMonth] - under this expression is =Parameters!SelectMonth.Value
All this are the factors in report. and when report runs I am able to see SelectMonth Parameter and able to select multiple months and data is been displayed accordingly I select the months.
But this is 50 % of requirement only done. Another requirement is I have to display months at the end of the report, which is written in UNION ALL query. I am able to display it by use of UNION ALL query. But the requirement is to display as per the month selected in parameter checkbox.
For eg. If I select Jan-Feb-Mar, than it should display as
Jan
Feb
Mar
Jan-Feb
Jan-Feb-Mar
But if I deselect for eg. Mar, than it should remove Mar from the Month which is at the end of report. Here I am able to remove from single month, as required month Mar is not showing/data is not been fetched in single month field but it is till fetching month Mar in end where it is joining months Jan-Feb-Mar. I do not even want that month Mar to be joined at end either. it should be removed totally from everywhere. it is should look like as below: but I am not able to do it.
Jan
Feb
Jan-Feb
If anyone can help that how should I put it ? I was wondering to use IF condition, that IF #SelectMonth = 'Jan' then only that much data should be displayed in single month column and even to the join month column.
But i am not able to figure out exactly. so please if anyone can help that will be great.
Thank you so much everyone in advance.
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.
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.
I have a dataset which looks like this
ProjectName MonthsThisYear CompletionDate
ProjectA 5 5/1/2013
ProjectB 7 7/15/2013
ProjectC 10 10/21/2013
I want to bar plot a graph where Y axis is project Name and X axis is January 2013, February 2013 ... December 2013.
Now the bar against projectA must be 5 units long, ProjectB is 7 units long and the bar for Project C should be 10 units long.
so that people can see that ProjectA is completed in May, ProjectB is completed in July and project C in October.
How can I plot this graph?
currently I can plot this correctly... but the X-Asix has 0, 2, 4, 6, 8, 10, 12 on it rather than month names.
I am on SSRS 2008 R2.
This is what I see right now
I just want to see month names and year on X axis.
Maybe some more question detail would be useful, but here's one way that works with your data:
The main issue we're facing is that typically a date is the category, but in this case it's actually the Data value, which gives us less control over the labels compared to a category group.
First, set up a chart with a Category Group based on ProjectName, and a Data expression like:
=DateSerial(Year(Fields!CompletionDate.Value), Month(Fields!CompletionDate.Value), 1)
i.e. the first of the month of each CompletionDate value, otherwise your bars will be between months.
Next, we need to sort out the X axis:
In my example I set Minimum to:
=DateAdd(DateInterval.Month
, -1
, DateSerial(Year(Min(Fields!CompletionDate.Value)), 1, 1))
i.e. December for the last year. Set Maximum to:
=DateSerial(Year(Max(Fields!CompletionDate.Value)), 12, 31)
i.e. the end of the year.
Set Interval to 1 and Interval Type to Months.
Format the X Axis to MMM yyyy.
Looks OK:
If you can actually add a Year column with a value 2013 or whatever, pretty much all of the expressions above can be simplified. For example, I've ignored MonthsThisYear, but if you have a Year column you can build the start of the month value based on MonthsThisYear and Year.