Switch & IIF Conditional Formatting in SSRS 2008 - reporting-services

I'm am having some trouble with conditional formatting in SSRS. I have tried Switch & IIF Statements (below). The report runs but is not returning colors as it I'm hoping it would. I'm trying to highlight dates which are <= today in red, and everything else will be black. Does it matter if this field is a date field? I've seeen other questions on here with the same issues but no resolutions. Was hoping today would be my lucky day to find an answer. Here is what I have tried and thank you in advance for any input.
=Switch( Fields!Decision_Must_Be_Made.Value <= today(), "Red",
Fields!Decision_Must_Be_Made.Value > today(), "Black")
=IIF( Fields!Decision_Must_Be_Made.Value <=today(), "Red", "Black")

Yes, it definitely matters if the field is a Date Time field. If it's a string, then you need to convert it to datetime first. How you do that will depend on the format of the string. But it will be much better if you can stick with a datetime field from the database. (I've seen where some will format a date to a string in the select of the sql query. Don't do that. Format as late as possible: in SSRS, at the text box level.)
If it is a dateTime, break up your formula to find out what's not working as expected and make it more visible, if only for debugging. Put this in the expression of a cell, for example:
=IIF( Fields!Decision_Must_Be_Made.Value <=today(), "Old", "New")
Edited to add information on where the color formula should be added:
Sounds like you don't have the IIF specifying the color in the right place. There are a few different places you could specify this: it needs to be in the properties of either the textbox or the placeholder. The value for these things should simply be your date field (=Fields.Decision_Must_Be_Made.Value) but the font color needs to be specified separately. One place to do this is in the Text Box Properties dialog. In the font pane, you need to specify the font color. The Fx symbol indicates that you can specify a formula. Click this button for a place to enter your '=iif...' formula.

Admittedly this does not answer your scenario but may help someone else. I had an issue where a stand-alone textbox using a scenario where I wanted to display an error message when there was either no record or duplicate records. My formula "=IIf(IsNothing(First(Fields!MyField.Value)) Or First(Fields!MyField.Value) <> Last(Fields!MyField.Value), "Red", "SomeOtherColorButNotBlack") which did not render the correct fore-color (came out "Black") however, doing a similar expression that equates to True or False on a Tablix or Matrix does work fine. Another one for MS to solve. I found my own workaround by setting the color to always be red and then the expression of the Text to be blank when no error.

Related

SSRS - Using iff(Instr(Fields! to find certain text in a string

I'm struggling (spending LOTS of time trying to figure this out) to make an iff statement work in SSRS/Report Builder.
I'm pulling a VARCHAR into a report. In the VARCHAR, consists of lots of words/text.
I'm trying to colour this textbox if this VARCHAR string contains the word "red" or "amber" or "green".
If it does find either of these words in the VARCHAR string, I would like it to colour the textbox the same colour as the text it's looking for.
If it finds "red" in the VARCHAR, the textbox becomes red in colour, etc.
I've looked on google and youtube lots and have found two potential solutions:
iff(Fields!note.value.contains("red"), "red", "white")
-Above I believe should look for "red" in the VARCHAR string and then fill the textbox red if it matches or white if no match?
iff(InStr()<0, [true], [false])
The second option I have no idea how this would work. I apologise that my syntax for vba is awful. Any help would be GREATLY appreciated. I'm trying to learn SSRS and/or Report Builder on the job.
Please note I'm using Report Builder ver 15 OR Visual Studio 2019.
Kind regards.
You should be able to use Tostring.Contains() like this... (I've used SWITCH rather than nested IIFs as it's cleaner in my opinion.
=SWITCH(
Fields!AddressLine1.Value.ToString.Contains("Street"), "Red",
Fields!AddressLine1.Value.ToString.Contains("Road"), "Green",
Fields!AddressLine1.Value.ToString.Contains("Ave"), "Orange",
True, Nothing)
The last True acts like an else. I've also used Nothing which is the default 'transparent'
I used this on a test dataset and applied the expression to the last column, here are the results....

changing background colour with expression for time value SSRS

I have an issue with changing colour of a column through an expression. The column of which I want tot change the background colour of has a time value. The format is hh:mm, currently I am using this expression:
=IIF(Fields!FacturatieTijd.Value >= 5, "Red", "Lime")
With this expression it only changes the colour of the cells which dont have a value in it(Null). I have tried using "05:00" in my expression but that gives an error..
Regards.
It seems like you're going to want to get the hours separated from your time to compare correctly. To do that, you'll need to use the Datepart function within your IIF. Try the following expression.
=IIF(DatePart("h", Fields!FacturatieTijd.Value) >= 5, "Red", "Lime")
In theory, this should extract an integer value for the hour and compare it against 5, giving you the result you need. I haven't actually tested this, but it should work.

Hide SSRS chart based on multivalue parameter

Good Afternoon,
I have a multivalue parameter where if the last value in the array has the value "Reentry", it should always display the report. However, if the last value in the array is not "Reentry" it should hide the chart because it doesn't apply to the other choice. The choices are Corrections, Reentry and All. I applied the following expression to the visibility option of the target chart.
=IIf((Parameters!Division.Value(Parameters!Division.Count-1)="Reentry"), True, False)
This is showing the report for all cases, even when I select only Corrections which is the value that appears in a textbox where I placed this expression, being the last value in the array.
=Parameters!Division.Value(Parameters!Division.Count-1)
I have tried all kinds of other ways to get this to work and I have been stuck for a day. I think this approach is the easiest but it is always showing the chart, no matter what is selected. Any thoughts? This shouldn't be so difficult...thanks in advance!
Try using this expression:
=IIF(
Array.IndexOf(Parameters!Division.Value,"Reentry")=
Parameters!Division.Count-1,True,False
)
Let me know if this helps.

Expression to hide subreport in SSRS

The following expression to show/hide subreport is not working.
=iif((DateAdd("d", 45, Fields!actualclosingdate.Value) > Today()), True, False)
Any suggestions, alternatives, or advice will be greatly appreciated.
Please try to put the subreport into a rectangle and set the visibility of that rectangle.
Most of the times issue with the SSRS value matching expressions are the data types of the values that creates the problems or undesired result. In your case your actualclosingdate field might be coming as the string so you need to make sure that it is convert back to the Date before adding days to it. For that matter always right your expressions in SSRS using type conversion so your expression can be on safer side.
And I am also assuming that your requirement is,
If the actual closing date +45 days is greater than Today then hide the report and if not then show.
SO Subreport->RightClick->Proprties->Visibility->Show/hide based on expression
=IIF((DateAdd("d", 45,CDate(Fields!actualclosingdate.Value)) > Today()), True, False)

SSRS- charts colour coding

I have SSRS solution for SQL 2005 and 2008.
I am showing output in the form of chart- column chart with each column representing different database.
Is there a way to display each column in different color?
Regards
Manjot
You can use a formula to set the colour of each column, but that would work best if you knew what the individual series values ('databases'?) were going to be.
Right-click on your chart and bring up its properties. Now switch to the Data tab and select the first item in the Values list. Click the Edit... button to show the properties for the values (the columns) in your chart. Over on the Appearance tab there's a Series Style... button which takes you to another dialog.
On this new Style Properties dialog, switch to the Fill tab. That's where you set the colour for each of your columns. This can be a formula, so you might make it something like:
=Switch(
Fields!Database.Value = "master", "Blue",
Fields!Database.Value = "msdb", "Red",
"Green")
If you don't know in advance which 'databases' are going to be represented on the chart, this method won't work very well. In that case you might be able to come up with a formula which hashes the database name and comes up with a colour to match. That sounds like an interesting challenge, so add to your question if you need help doing something like that.
Edit
I just got a hash-based-colour-scheme working. It's a pretty nasty piece of code, but it did manage to get me a unique colour for every (string valued) column. Perhaps someone can come up with a better algorithm and post it here. Here's mine:
="#" & left(Hex(Fields!Database.GetHashCode()), 6)
So that's getting the HashCode for the string (a numeric value) and converting it to hex, then taking the leftmost six characters and prepending it with a "#" sign. That gives us a string that looks like a colour value (eg #AB12F0).