changing background colour with expression for time value SSRS - reporting-services

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.

Related

SSRS Switch Colour Expression multiple groups criteria

I trying to colour code a group within a group based on a value.
enter image description here
I am quite new to SSRS, and have tried various expressions, SWITCH, IIF etc but I cant seem to get them to reference the various criteria and groups correctly.
You've not explained what your criteria is so this is just a guess. I'm also assuming that the Target values are numeric, so 5 and not 5 days for example.
I'm also assuming that you want the background to be green is the count of DAYS2 >= Target
If this is the case then you can do something simple like this
=IIF(COUNT(Fields!DAYS2.Value) < Fields!Target.Value, "Green", "Red")

Conditional expression for Background color in SSRS

I have a matrix in my SSRS 2016 reporting services report. I am trying to set a conditional expression on background color for the sum(field.value). This field is formatted as a percent. Here is my expression which does not appear to have any errors:
Background Color Expression:
=Switch(Fields!PicturesbeforeFirstSignoutCount.Value<.80,"Red",Fields!PicturesbeforeFirstSignoutCount.Value >= .80 and Fields!PicturesbeforeFirstSignoutCount.Value < .95,"Yellow",Fields!PicturesbeforeFirstSignoutCount.Value >= .95,"lightGreen")
Problem: It turns everything "lightgreen" even when their textbox should be yellow's and red's in the matrix. there is one field that is highlighted as Red, but it should have been Yellow.
I tried to set this in the field property for background color expression. That just made everything "light green".
I changed it to the fill expression in the matrix Text box. Now I get mostly everything green except the one red field that should be yellow. I checked my numeric values and they are coming across in decimals points when I change the format back to number
Any help would be appreciated.
As Harry mentioned in the comments, you need to be evaluating the same expression as you are displaying.
Also you can simplify the SWITCH statement as follows.
=SWITCH(
SUM(Fields!PicturesbeforeFirstSignoutCount.Value) <.80, "Red",
SUM(Fields!PicturesbeforeFirstSignoutCount.Value) < 0.95, "Yellow",
True ,"LightGreen"
)
As SWITCH returns the first result where the expression is true, there is no need to put a range in. so if the value was 0.91 then the first expression would be skipped but the second one would be true to it would return "Yellow".
The final True acts as an "else".

In SSRS, when my value is NaN, how do I use that in an expression?

My dataset in the report is using an MDX query and I cannot change that query (don't even know how to; it was written by someone else). The MDX Query is outputting a decimal value for the field in question, and I am formatting it as a percent in the report. In some cases this field's value is NaN (before and after formatting).
This report contains an expression that changes the background color of that report cell to red if the value is over 0% Here is the formula:
=IIf(FormatPercent(Fields!Payment_Amount_Difference.Value) > FormatPercent(0) and Fields!Campaign_Year.Value >= 2016, "Red", "white")
This is working great except for when the value is NaN. The background color of NaN is red and I have been asked to make that not happen.
I have tried IsNumeric, but NaN is being perceived as numeric (I tested this by adding an additional column to the report and using an iif function to say "if numeric then yes, if not no").
I tried IsNothing also and that doesn't work. Tried "NaN" as a string in the expression and that also failed.
Any ideas for changing NaN to something else inside the report or adjusting my background color expression? The goal is for a field containing NaN to have a white background.
I've never used it but you can try the IsNaN .Net function.
=IIF(Fields!Campaign_Year.Value >= 2016 AND
IIF(Double.IsNAN(Fields!Payment_Amount_Difference.Value),
0.0,
Fields!Payment_Amount_Difference.Value
)
> 0,
"MistyRose",
"White",
)
Also, you don't need the FORMATPERCENT for the numbers to compare them. And I prefer something a little subtler than Red.
I've not tested this against NaN but this might work.
=IIf(VAL(Fields!Payment_Amount_Difference.Value) > 0 and Fields!Campaign_Year.Value >= 2016, "Red", Nothing)
All I've done here is remove the FormatPercent function, as others have said - there is no need for it when comparing numbers to numbers. I then used VAL to convert the field to a value even if it contains a string.
I've never used this to try to convert NaN to zero before and I'm not in a position to test right now but it should work.
I also swapped out "White" for Nothing this is the default background for a textbox (basically transparent).

Change colors on based on expression

I have percentage calculated field and it has to have different color based on values:
where <70% is red
70% to 79.9% is Yellow
80%+ is green
I tried:
=Switch((Sum(Fields!TotalQtySUM.Value, "DataSet1")/Sum(Fields!REG_HOURS.Value, "DataSet1")) < 0.7, "Red" ,
(Sum(Fields!TotalQtySUM.Value, "DataSet1")/Sum(Fields!REG_HOURS.Value, "DataSet1")) < 0.8, "Black",
(Sum(Fields!TotalQtySUM.Value, "DataSet1")/Sum(Fields!REG_HOURS.Value, "DataSet1")) >= 1, "Green")
And:
=IIF((Sum(Fields!TotalQtySUM.Value, "DataSet1")/Sum(Fields!REG_HOURS.Value, "DataSet1")) < 0.7, "Red" ,"Green")
They either all red or change the colors randomly without following any rules
Where did I go wrong?
I think your first operator is overriding your other operator: '< 0.7' is true for the color before '< 0.8'. Try to reverse the first two criteria and that may fix your issue. I ran into something similar to this and I believe this is how I fixed it. Also you don't need to do Sum(Fields!(Field).Value, "(Dataset)"), You can just do this: "Sum(Fields!(Field).Value)".
The second criteria you gave though I would test the value you are getting by itself. It seems the second set may be valid but the expression may not be what you are expecting.
Also I would just add a 'computed' field to my dataset instead of doing it in an expression. This may be faster than the expression evaluation in the end. The more expressions you use in SSRS the slower the report becomes. I know when an expression does not work for setting a property I usually go through the parts piece by piece.

Switch & IIF Conditional Formatting in SSRS 2008

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.