Conditionally Coloring Cells in SSRS - reporting-services

I am working on optimizing a report that I have in SSRS and am having some difficulty with a line of code. Essentially what I want is for a check to be made if the cell is blank, or if it has data. If it is blank I need the cell color to change to red. If it has data I need it to stay transparent. Here is what I have written.
=iif(Isnothing(Fields!MedServices.Value)= "True", "Red", iif(Isnothing(Fields!MedServices.Value)= "False", "Transparent"))
When I go to save this though I get the below error:
The BackgroundColor expression for the text box ‘MedServices’ contains
an error: [BC30455] Argument not specified for parameter 'FalsePart'
of 'Public Function IIf(Expression As Boolean, TruePart As Object,
FalsePart As Object) As Object'.
I know this must be a stupid error on my part with parenthesis, but I cannot figure out where I have made the error. Any help is appreciated.

IsNothing() function returns a boolean data type, true or false it is a valid expression for the IIF() function.
Try:
=iif(Isnothing(Fields!MedServices.Value) or Fields!MedServices.Value="",
"Red", "Transparent")

Related

SSRS tablix visibility

I have a multi-parameter report in SSRS where I want to display or hide a report depending on the parameter selection. If the user selects only one facility from a multi-value facility parameter then I want a second report to display along with the main report(it would be a separate tab). If multiple facilities are chosen then I only want the main report to display.
I've been playing with the visibility expressions on the second report but I can't seem to get it to work.
I've tried:
=IFF(Parameters!entity.IsMultiValue, "True", "False")
but that returns an error "The hidden expression used in tablix returned a data type that is not valid.
I've also tried:
=IIF(Parameters!entity.Count = 1), "False", "True")
But I get the same error. I'm using SSRS 2016.
False and True are not strings but constants.
Change it to:
=IIF(Parameters!entity.IsMultiValue="Your value", True, False)
And the second one to:
=IIF(Parameters!entity.Count = 1, False, True)
Good luck.
True and False are not strings, they are booleans. The Visibility property looks for a boolean, but in the expressions you gave (assuming your syntax was correct when testing it), you are passing strings since you have them enclosed in double quotes. Remove the double quotes and that will clear that error.
You also don't need to use IIf here -- you can simply use the first argument of the IIf, since that by itself will evaluate to True or False. I doubt there is any appreciable performance difference, but just a small thing to note.

SSRS Parameter Specify Values - Expression Not Working

In SSRS, I am trying to use an expression to specify the available value for a text box parameter. I have tried several different things but my text box never gets populated with data. For the purpose of this post I have made the expression as simple as possible. Below is an example. The parameter is defined as single-value, non-blank, non-null, and visible.
Custom Code:
Public Shared Function TestFunc() as String
return "test"
End Function
Parameter Label: =Code.TestFunc()
Parameter Value: =Code.TestFunc()
In this simple example I would expect the text box parameter to have the value 'test' but this is not the case. What am I missing here? Is there a different syntax or a setting that I'm unaware of?

If field is NOT null, then hide an object (SSRS Expression)

I have a rectangle.
I want to hide it if a field (X) is NOT NULL.
I tried this but it is not working:
=IIF(NOT IsNothing(Fields!filepath.Value), 1, 0)
I get the error:
An error occurred during local report processing.
The Hidden expression used in rectangle 'ID2398' returned a data type that is not valid.
Anyone know why I'm having this issue?
Do I need to place the actual field onto the report? I tried it but I keep getting the same error.
If you're using that for the Visibility expression, I believe you need to explicitly use True/False rather than 1 or 0. So try:
=IIF(NOT IsNothing(Fields!filepath.Value), True, False)
I do prefer to use =iff(Fields!filepath.Value IsNot Nothing, Fields!filepath.Value, ) in Textbox/Properties/Visibility/Hide as it is more intuitive for me.

Dealing with blank or null in ssrs

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)

SSRS Expression Evaluation Issue

I'm having an issue with expressions within reports. I'm coloring the background of a textbox within a table depending on the value within it. The text in the field relates to backups for a SQL Server. The value is either a date or the text "Not Yet Taken". If the date is more than 2 days old, I want the background to be yellow. If its more than a week old or if the date value is "Not Yet Taken", I want the background to be red. Otherwise, it'll be green.
The problem I've been having since I started with reports for SSRS (a few weeks ago) is that my expressions seem to get fully evaluated. An IF statement will have both its true and false values evaluated even though only one of them will be used.
This becomes a problem because "Not Yet Taken" is clearly not a date and to work with the dates I need to convert the date string into a date. Here is the code I have currently:
=IIF(Fields!LastBackUpTaken.Value = "Not Yet Taken","Red", IIF( IsDate(Fields!LastBackUpTaken.Value) = true,
IIF( CDate(Fields!LastBackUpTaken.Value).AddDays(Parameters!DaysTillExpiry.Value).CompareTo(NOW()) = 1,
"GreenYellow",
IIF( CDate(Fields!LastBackUpTaken.Value).AddDays(7).CompareTo(NOW()) = 1, "Yellow", "Red")),
"Red"))
So basically, the expression reads "If LastBackUpTaken.Value = "Not Yet Taken", return the color Red. If it isn't "Not Yet Taken", check to see if the string is a date. If it isn't a date, return the color Red. If it is a date do calculations and return the appropriate color.
This expressions works for all the text fields that don't have "Not Yet Taken" as its text. For the fields that do have "Not Yet Taken" as its text do not have any color set.
EDIT: I also get a conversion error that I forgot to mention, whenever the text is "Not Yet Taken"
Any ideas?
Write a VB function to return the color string in the Code Tab of the Report Properties. Here you can use language constructs you are comfortable with (case statements, regular if statements, etc.). Logic with be easier to read back as well.
Public Function GetBackgroundColor(ByVal DateString as String) As String
'plain old vb syntax here
End Function
In the expression for the background color property:
=Code.GetBackgroundColor(Fields!LastBackUpTaken.Value)