SSRS Reports - Formatting Date Column using expression - reporting-services

I am using SSAS cube to display data in my report. There is a date column in the cube which may be blank. If it is blank I need to display blank otherwise I need to format it as "MM-yyyy". I am using the below mentioned expression in the column.
=IIf(Trim(Fields!Chargeoff.Value) = "", "",
Format(CDate(Fields!Chargeoff.Value), "MM-yyyy"))
The rows which have date values are perfect with the correctly formatted date being displayed. However for blank rows, it displays error saying
The Value expression for the textrun ‘Chargeoff.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from string "" to type 'Date' is not valid
I tried with IsNothing, Null and everything else that came to my mind but could not get to display blank.
Does anyone have any suggestions on how to do this?
Update
I actually formatted my date in SSAS instead of SSRS.. That did the trick for me..

=IIF(CDATE(IIF(TRIM(Fields!RequiredStart.Value).ToString().Length = 0,
"1/1/0001",
Fields!RequiredStart.Value)).ToString() = CDATE("01/01/0001"),
"",
Format(CDATE(IIF(TRIM(Fields!RequiredStart.Value).ToString().Length = 0,
"1/1/0001",
Fields!RequiredStart.Value)), "dd-MMM-yyyy"))
:)

try putting and Empty Date in for the output instead of an empty string. 00-0000 it is looking for a Date and you give it an empty String. I would imagine that you either have to give it an empty date or a Default Date

Related

Conditional formatting for current day date

I am just trying to getting my data to do a color fill if the date value equals today.
The data is coming from oracle:
=IIf(Fields!finishDATE.Value = Today(),"Yellow","Transparent")
This will not give me any errors nor will it do the function according to the expression. None of the data with the finish date equaling today highlights.
If today is 8/24/2021 it should look like this:
3/22/2021, 8/24/2021, 2/22/2021
As I'm not sure what format the data will come in from Oracle (I'm a MS SQL person) then this might be overkill but try this
=IIF (Format(Fields!finishDATE.Value, "yyyyMMdd") = Format(Today(), "yyyyMMdd"), "Yellow", Nothing)
All I'm doing here is comparing just the date parts of the date/datetime values.
Below is the output. The first column is the actual date column contents including a time, then for illustration only, the 2nd column shows it formatted to just the date part and the 3rd column show today() with the same format applied.
Finally, I used the keyword Nothing (SSRS almost equivalent of NULL) as this is the correct default value.

Trouble filtering on paramteter in Report Builder

I am having trouble filtering my table on a parameter and keep getting the error:
"The FilterValue expression for the dataset ‘DataSet1’ contains a colon or a line terminator. Colons and line terminators are not valid in expressions."
Filter is...
Expression : Month Date/Time
Operator : >
Value: =IIF(Parameters!City.Value = "Dallas", 8/1/2018, 10/1/2018)
When I put just a date in the 'Value' box the query works fine. It is when I try to link to parameter I start getting issues.
Just wrap a CDate() around it. Also check if your report language is set to a value.
'Expression with a Date/Time Filter
=IIF(Parameters!City.Value = "Dallas", CDate("8/1/2018"), CDate("10/1/2018")

SSRS IIF expression giving only partial output

I have a simple IIF statement to say if the actual date is blank, show me TBC. Otherwise, show me what the actual date is. I can successfully get the TBC. But I cannot get the actual date to show where I know there is a date. Any help is appreciated.
=IIF(Fields!VPSR_Actual_Date.Value = "", "TBC", Fields!VPSR_Actual_Date.Value)
I'd do a check if the column is null or zero string and then format the date.
=IIF(IsNothing(CStr(Fields!VPSR_Actual_Date.Value)) OR CStr(Fields!VPSR_Actual_Date.Value) ="", "TBC", Format(Fields!VPSR_Actual_Date.Value, "dd-MMM-yyyy"))

SSRS Sorting and Renaming an Empty String

I'm building a bar chart that has many values and one of the values is an empty string. When added in SSRS, the blank string returns a '1' value (The first bar on the chart). How do I change the name from '1' to Blank? Also, how do I sort an Blank string within the chart?
Here's what I tried on changing the name to 'Blank' and it doesn't seem seems to be working:
=iif (IsNothing(Fields!AGE.Value), "Blank", iif(CSTR(Fields!AGE.Value)= "", "Blank", CStr(Fields!AGE.Value)
Here's what I tried to sort and can't get it to work..probably because to empty string is messing me up. I'm only showing a sample below otherwise the code would be too long.
=Switch(Fields!Age.value="INCORRECT", 1, Fields!Age.value= "AO", 2,true,3)
Thanks in advance for your help!
#rajeshpanchal - thanks for pointing me in the right direction. I went back and changed my SQL query to include the empty strings within the Case statement. Something like Case when fieldname = '10' and fieldname = '' then 'Blank Profile'
Once I had the empty string named to something other than '1', then I was able to sort my chart within SSRS by creating a new calculated field and using the following Switch function:
=Switch(Fields!Age.value="INCORRECT", 1, Fields!Age.value= "AO", 2,true,3)
I then went to the chart data, right clicked on the category group and choose category group properties..then clicked on sorting and input my newly created sorting field. I was trying to get the INCORRECT bar to show first on the chart and you can see below that it worked.

SSRS and null datetime

I always thought that when a stored procedure brought back a null datetime that an SSRS report would show mindate in that cell. The thing is, in my experience this is not always true. I can't figure out why. Sometimes a report will show blank and sometimes mindate for a null datetime. Why is that?
Is there rules or documentation (that makes sense) that explains how this works? It's hard to be consistent when the tools you are using are not consistent. I can make two reports that are set up exactly the same way. One will show mindate and one will show blank for null datetimes. I don't get it.
EDIT:
First of all, yes the mindate thing has happened to many.
https://www.google.com/search?num=50&q=ssrs+null+date+show+blank&oq=ssrs+null+date+show+blank&gs_l=serp.3...8759.9774.0.9941.10.10.0.0.0.0.152.888.8j2.10.0....0...1c.1.25.serp..8.2.166.kl2WBVx4Ijw
Almost every result has someone talking about the mindate when they want a blank. Many of the results are from Stack Overflow so before you start telling me it never happens, realize you are flat wrong. You may have never seen it. I have never seen a severed finger in my food in all my years of eating and thousands of meals. Doesn't mean it hasn't happened to someone.....
Example of one that is showing min date:
In the report the expression for the text box is:
=Fields!SecondaryInjuryRecordDate.Value
The number formatting was set to Date->01/31/2000 in the placeholder properties window.
Pretty straightforward, nothing weird going on there. RIGHT?
In the proc, the code for that column is:
CASE WHEN ISNULL(l.SecondaryInjury, 0) = 0 THEN '' ELSE l.SecondaryInjuryDXDate END AS SecondaryInjuryRecordDate
That resulted in mindate being shown whenever SecondaryInjuryDXDate was null. I had to switch to this:
CASE WHEN ISNULL(l.SecondaryInjury, 0) = 0 THEN '' ELSE ISNULL(l.SecondaryInjuryDXDate, '') END AS SecondaryInjuryRecordDate
...to get blanks when the date was null.
SecondaryInjuryDXDate is a DATETIME and
SecondaryInjury is a bit.
Within SSRS, by default a NULL DateTime value will be represented as an empty string instead.
If data formatting is applied to the value, a MIN DateTime value will be used in place of the null value e.g.: converting the DateTime to a ShortDate as described:
The number formatting was set to Date->01/31/2000 in the placeholder properties window. Pretty straightforward, nothing weird going on there. RIGHT?
To avoid this, the column value must be wrapped in an expression to conditionally apply the required formatting:
=IIf(IsNothing(Fields!DateTimeField.Value), "", FormatDateTime(Fields!DateTimeField.Value, DateFormat.ShortDate))
Use something like this in textbox expression:
=IIf(IsNothing(Fields!DateTime.Value), "", Fields!DateTime.Value)
It looks like there is no documentation to be found about this. The next best thing is to have this Q&A document things based on our collective experience.
Supposing the question: "What does SSRS do when displaying a DATETIME with a NULL value?"...
...the answer is it will display an empty string instead. There is no reproducible scenario where a NULL value would be displayed as anything else, unless you do some work to that end yourself, for example:
If the query COALESCEs the NULL to something else, e.g. the string "NULL" or a MIN DATETIME;
If you have an expression for the textbox value, e.g. IIF(Fields!MyDateTime.Value Is Nothing, "01-01-1900", Fields!MyDateTime.Value)
Every field returned in a SQL query gets a datatype assigned. Generally, you want to keep dates returned as dates from SQL, not as strings. (Don't format the date to a string in SQL. Do that as close to the presentation layer as possible.)
So instead of this in your query:
CASE WHEN ISNULL(l.SecondaryInjury, 0) = 0 THEN '' ELSE l.SecondaryInjuryDXDate END AS SecondaryInjuryRecordDate
I would try to use:
CASE WHEN ISNULL(l.SecondaryInjury, 0) = 0 THEN CAST( NULL AS DateTime ) ELSE l.SecondaryInjuryDXDate END AS SecondaryInjuryRecordDate
See SQL cast datetime for an explanation of why you are getting 0 cast to a date.
I did find when I format an entire column such as FormatDateTime(field, DateFormat.ShortDate) - SSRS will format that blank field to 01/01/0001. Just an FYI.