Question

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")
Was it helpful?

Solution

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.

Text Box Properties font pane

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top