I'm having trouble determining if an SSRS 2016 text report parameter is null or blank. Here is my parameter's properties:
And this is the expression I'm using to display it. If it's non-null or non-blank I want to display it as a formatted date, otherwise "N/A".
=IIF((Parameters!EndDateTime.Value = "") OR IsNothing(Parameters!EndDateTime.Value), "N/A", Format(CDate(Parameters!EndDateTime.Value),"dd MMM yyyy HH:mm:ss"))
But when I run the report I get "#Error" if the value is blank:
What am I doing wrong here?
Thanks.
This is because the IIF() function evaluates always both arguments. Here you will find more information about it: IIF Evaluation
You either go with the IsDate() function to check if it is a date before you convert it or you can use a Switch() statement.
Related
Hi all, I have an expression in SSRS that calculates the Due date from the Last Fit Test. The data is correct if the Last Fit Test has a date. However, if the Last Fit Test is Null or blank, it gives an error "########" (it supposes to return empty or blank). How can I fix that expression?
=IIF(IsNothing(Fields!LastFitTest.Value) = True,"",DateAdd(DateInterval.Year,1,Fields!LastFitTest.Value))
Try this ...
=IIF(
IsNothing(Fields!LastFitTest.Value),
"",
DateAdd(DateInterval.Year,1,IIF(IsNothing(Fields!LastFitTest.Value), '1900-01-01', Fields!LastFitTest.Value))
)
The problem was the IIF always evaluates both the true and false condition so when you had no value in LastFitTest the false side could not evaluate even though it would never be used.
All we have done here is made the date that get processed in the DateDiff function always return a valid date. The 1st Jan 1900 means nothing, you can put any date you like in there as it will never be used in the final result.
The only other change was to remove the = True. IsNothing returns True/False so you don't have to explicitly say =True.
When i am creating SSRS report getting error like" the value expression for the text box "" has a scope parameter that is not valid a lookup function."
It seems that you have a LOOKUP function in an expression that is using an incorrect value for the dataset score.
In this example, Product" is the scope.
=Lookup(Fields!SaleProdId.Value, Fields!ProductID.Value, Fields!Name.Value, "Product")
Since it doesn't give the text box name, the expression with the Lookup must be in some other object.
I am using below expression in SSRS but is not giving expected result.
=IIf(Fields!Completed_Date.Value Is Nothing,
Nothing,
IIf(First(Fields!TIMEFORMAT.Value,"dsPreferences") = True,
Format(DateAdd("n",Parameters!UTCOffset.Value,Fields!Completed_Date.Value),"MM/dd/yyyy hh:mm:ss tt"),
Format(DateAdd("n",Parameters!UTCOffset.Value,Fields!Completed_Date.Value),"MM/dd/yyyy HH:mm:ss")
)
)
It has to check if Date is null.If it is null just leave field blank.If it is not null then it has to return value according to Time zone value that it is getting from another dataset.This expression works fine when there is non null date but it returns #error when there is Null date.
Try using this syntax:
=IIf(IsNothing(Fields!Completed_Date.Value), "", <yourFalsePart>)
This syntax probably doesn't solve your issue because Completed_Date is also used in the false part. IIf operator will always evaluate both expressions before deciding which one to use: so if Completed_Date is Nothing it will broke your expression anyway.
Try using a Custom Function as explained here: SSRS expression giving error with iif condition
In my report, I have an expression which is used to pass a parameter to a child report parameter which is set to allow null values. The expression is :
=IIf(Parameters!Lead.Value = "False",Nothing,Fields!Paid.Value)
The above expression returns values only when Fields!Paid.Value is not blank. Therefore when Fields!Paid.Value is blank I get an error
"the value provided for the report parameter is not valid"
How do I modify my expression to parse these two conflicting issues?
What I want is to be able to return values when the Fields!Paid.Value is blank or when it is not. So at all time when the expression runs corresponding values are returned without the error stated above.
Thanks for helping out.
The first thing you do, wherever you have used the "Paid" parameter, set it to allow null value. Allow null only not blank.
The second thing about the expression, use something like this,
=IIF(Parameters!Lead.Value "FALSE", Nothing, IIF(IsNothing(Fields!Paid.Value),0,Fields!Paid.Value)
My datasource is XML (sharepoint list). I basically want to show the date formatted if the value in the field is a date and if not then show "NA". For some reason, even when the data is a a string it is still trying to convert it to a date somewhere. Here is my code..
=IIF
(
ISDATE(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#","")),
formatdatetime(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#",""),2),
replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"string;#","")
)
The problem is that the IIF statement in SSRS doesn't short circuit, it always evaluates both conditions, so even if the field is not a date, it still tries to do the formatdatetime function.
(See this: SSRS iif function question)
Instead of the IIF function, try using the SWITCH function instead:
=SWITCH(First(Fields!ows_Manufacturing_Date.Value, "DataSet1")="string;#NA",
"NA",
First(Fields!ows_Manufacturing_Date.Value, "DataSet1")<>"string;#NA",
formatdatetime(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#",""),2))