Reporting Services 3.0 Chart calling stored procedure with date time value , how to sort? - datetime-format

I have a Stored Procedure in SQL Server 2008. One of the values returned is:
SELECT DATEADD(mm, DATEDIFF(mm,0,e.Day), 0) AS [Month],
So I get values like: 2012-05-01 00:00:00.000
I want to display the month in the X axis for a chart report, obviously sorted chronologically. It would be great if I can display the month as "May-2012" or "2012 - May". Right now it displays the whole thing as 5/1/2012 12:00:00 AM and it is sorted alphabetically instead of by month.
When I check the Sorting it shows the field [Month] and order A to Z, so I assume it is not "seeing" it as a datetime value.
How do I get the sorting right?
How do I change the format to display the month as "May-2012" ?
Thanks in advance!

OK, work around:
I talked to my DBA, asked him to return a formatted field from the stored procedure, with values like "2012-05" and '2012-12' and sort by that field. Then I used that new field on the Report builder Chart, and remove all sorting.
Works for now, but still need to understand how to do it right for future reports.

Related

Crystal Reports - Combine Rows

I'm very new to Crystal Reports and I've one little problem.
I'll be quick and on point.
The columns are as follow:
2016-01-05, 2016-01-06, 2016-01-07, 2016-01-08, 2016-01-09 (list goes on till end of year)
These dates come from Database field called NextDueDate and it populates the report with all the dates.
My question, is it possible to combine these rows or group them by weeks or perhaps by month?
Result I'm looking for is:
2016-01 (All january days combined here) or something like maybe even just January etc.
NextDueDate field is type string by the way.
Also, I'd like to do this without getting involved in the actual database itself due to specific reasons.
you can use this simple formula as
#year_month = left ({NextDueDate},7);
create formula as year_month
and put left ({NextDueDate},7); in formula editor click on save.
now you can see this formula under formula field in field explorer.
Drag this one to your detailed section.
You can group the result based on this formula.
OR
user these formula
#year_month = left ({NextDueDate},7);
#monthOnly = right( #year_month , 2);
#FullMonthName = if #monthOnly = '01' then 'January'
else if {#month} = '02' then 'February'
........................................
else 'December';

SSRS report with stored procedure Dataset and aggregation by month - how to handle "empty" months?

I have a SSRS report which calls a stored procedure to return a two columns dataset - one column is a Date and the other is a calculated column I created to show the month in the format MMM-YYYY.
Using this dataset I have created an aggregated bar chart report which shows the number of records per month for each month value which has at least one record in the dataset, however I would like to be able to include on the chart any months within the range of the dataset even if they do not contain any records.
So for example, where at the moment I see the following data points on my chart:
Month Count
----- -----
Oct-2015 2
Nov-2015 5
Jan-2016 3
Feb-2016 6
Dec-2015 is missing because my Dataset didn't return any records for it, so I would like to be able to plot a zero Count value on the chart for this month.
Now I know how I would normally do this in SQL, with some kind of calendar table LEFT JOINed in so that I can return the months with zero counts, but can I achieve the same in SSRS with a stored procedure as the target of the main dataset?
If your grouping is on a date/time (or a number), you can make the axis type for it Scalar.
Create your chart, with Count as the value and Month as the Category Group
Right-click the grouped axis (horizontal in my example below) and go to the Axis Properties
Change the Axis type to Scalar, and change the Interval type to Months
Still in the axis properties, change the Number Category to Date, and the Type to Jan 2000 (or use a custom format)
My first instinct was to aggregate by an actual date, converted to the first of the month, instead of your MMM-yyyy string. However, it appears that SSRS (2008 R2 in my case) recognises text in the format MMM-yyyy as a valid date, so your existing procedure shouldn't need changing.

SSAS 2012 DAX SamePeriodLastYear() with Date Dimension

I have a date dimension and a fact table. I have two measures:
WorkOrdersCount:=
count(
FactWorkOrderLifeCycle[Clientsid]
)
and
WorkOrdersLastYearCount:=
CALCULATE(
count(FactWorkOrderLifeCycle[Clientsid]),
SAMEPERIODLASTYEAR(DimDate[FullDate])
)
WorkOrdersCount is simple and works fine. I thought WorkOrdersLastYearCount would be simple as well, but I now realize I don't understand SAMEPERIODLASTYEAR().
My date dimension has a DateSID column containing an integer representation of date as YYYYMMDD. It has two recordkeeping rows with SIDs of -1 and -2 for unknown and TBD dates. I'm only using the -1 row in this solution. The data is stored in a SQL Server table and the FullDate column is a "date" type. The actual value is 1900-01-01.
My fact, FactWorkOrderLifecycle, has a field called InvoicedDateSID that can have a null value which I replace with -1.
No errors are thrown in Visual Studio or when processing the olap, but upon referencing the column in a pivot table I get the following error:
ERROR - CALCULATION ABORTED: Calculation error in measure
'FactWorkOrderLifeCycle'[WorkOrdersLastYearCount]: An invalid numeric
representation of a date value was encountered.
Things I've tried (not all make sense):
changed SID values to positive integers
changed date value in dimdate to 9999-12-31 instead of 1900-01-01 when I saw that DAX dates might start at 1900-03-01
adding other dimensions to the pivot first to see if the formula calculates correctly at all.
I'm a DAX noob and I'm not sure how to troubleshoot this. Any help is appreciated!
Make sure you calendar table is indeed using a Date data type.
Remove any time component of your dates.
Make sure there are no gaps and no duplicates in your Calendar table.
Make sure you are using fields from your Calendar table on the pivot, and NOT date related fields from your data table.

SQL Server Report Builder : Concatenate data type "date" and "time"

I am working with SQL Server Report Builder 2008 R2.
I have a dataset that contains DateEntry (date, null) and TimeStampAuto (time(7), null) columns. I am trying to write an expression for concatenating those two values, so I can put it under DATETIME column on the report table. I tried the following but it does not work. It displays "#Error."
=First(Fields!DateEntry.Value, "Report1) & " " & First(Fields!TimeStampAuto.Value, "Report1)
When I just put the first part of the expression shown above, the report displays the date with some random time value (5/1/2015 12:00:00 AM). However, I did not put any time value in DateEntry. I only put the dates.
When I put the second part of the expression shown above, the report displays correct time that the data has.
I don't know why I can not concatenate those two.
The system type of the DateEntry.Value will be a DateTime value which is the readon that your report is showing 5/1/2015 12:00 AM even though it is only a date field in the database.
You need to format the date to only include the day,month and year to remove the included default time of 12:00 am
you will probably need to check for null values in both your date and time fields. you will also need to format the time filed to exclude any default date information.

display image on a report based on two date

I am using sql server 2005 reporting service to generate report base on a database. There are two columns which are datetime type ColumnA and ColumnB. The report would display a KPI image on this report by comparing these two columns.Below is the expression for selecting image
SWITCH(DateDiff("d",Fields!ColumnA.Value,Fields!ColumnB.Value)<0,"kpi_r",
DateDiff("d",Fields!ColumnA.Value,Fields!ColumnB.Value)>0,"kpi_g",
DateDiff("d",Fields!ColumnA.Value,Fields!ColumnB.Value)=0,"kpi_y")
For most of the records, the image is correct. Only for one record, the result is very strange.
For this record
ColumnA=2010-04-23 08:00:00 ColumnB=2010-04-22 17:00:00
It would display kpi_r, it displayed kpi_y. I have checked the value of DateDiff(d,Fields!ColumnA.Value,Fields!ColumnB.Value) in the SSMS, the value is -1. Why does it display kpi_y? Does anyone meet this problem before?
Best Regards,
The difference is that the SSMS DATEDIFF function counts the interval boundaries between the two dates whereas ReportBuilder counts the actual intervals. Within SSMS if you cross midnight you have triggered a day boundary so in your example you get -1. In ReportBuilder it is looking for 24 hours to be between the two values so you get 0. If you change the time on ColumnA to be '2010-04-23 17:00:00' you will see the value changes to -1 as you expected. For your comparison it would probably make sense to strip the time component from ColumnA and ColumnB when you do this SWITCH statement.
the above answer is spot on.
here's a few ways to strip time off a date depending on your preferences:
1. do it in RS: use and expression like dateserial(year(Fields!ColumnA.Value),month(Fields!ColumnA.Value), day(Fields!ColumnA.Value)) in your switch expression
2. do it in SQL: use an expression like cast(round(cast(ColumnA as float),0,1) as datetime) in your query

Resources