SSRS Expression for Cell backgound color based on cell to the left - reporting-services

I'm trying to write a field expression for a Cells in my report where I have to change the background color of the cell depending on the value in the cell to the left. Ex: if the cell to the left does not have the same vaule in it, the cell should show a red background color.
I tried the following:
=IIF(Fields!cell.Value, cell.left "value", "Red")
Image for the example is this,

There's not a way to refer to certain cells within a table in SSRS.
I think the best way to do this would be to use the same expression that you are using the two cells in your comparison for the Background Color expression.
=IIF(Fields!Lot_QTY.Value = Fields!Allocated_QTY.Value, "White", "Red")
Your data might be using a SUM:
=IIF(SUM(Fields!Lot_QTY.Value) = SUM(Fields!Allocated_QTY.Value), "White", "Red")
The only issue is if you are using a matrix for the data but that doesn't seem likely given your data.
The text box Expression is where you put the value to display in the cell. The properties are used to control things like the BackgroundColor, Font Color, Font Weight, cell border color...

Related

SSRS cell formatting

I have requirement to change the background color of cell based on DB flag.
This are the possible flags:
flag="1" background color of full row should be Green
flag=2 background of full row should be RED
flag=3 only particular cell should be highlighted with background as Yellow.
Currently I have added expression on every cell to check flag but it is creating performance issue. Is it possible to add/remove cell level expression dynamically?
I will add expression at row level and add/remove cell expression based on flag.
I would add a Calculated column to the dataset which does the check and returns the proper color.
=IIF(Fields!flag.Value = 1, "GREEN",
IIF(Fields!flag.Value = 2, "RED",
IIF(Fields!flag.Value = 3, "YELLOW", "BLACK")
Then set the Background color to that new field.

Conditional Formatting not working on specified cells in SSRS

I have got a report that consists of several matrices aligned right next to each other.
Not all the cells of the report contain data and appear as blanck cells so i created the following statement in order to have "N/A" on all cells that have no value:
=IIf(isNothing(Fields!Belfast.Value),"N/A",Fields!Belfast.Value)
and what i need to do is to give all cells that have the "N/A" value to have a colour so i created this statement in the Text properties under the Fill Menu:
=IIf(Fields!Belfast.Value = "N/A","#faa1a1",Fields!Belfast.Value)
but when i preview the report no cells containoing "N/A" are changing colour according to my cell Fill statement.
what am i doing wrong?
There's no problem with your first expression. However, an expression like this will only change the value in the Report Item. The values in your dataset results will be unchanged, even in the context of the cell you've put the expression in.
One way to get the desired results is to use the same logic from your value expression in your colour expression:
=IIF(IsNothing(Fields!Belfast.Value), "#faa1a1", "Black")
Alternatively, you can check the Report Item value to use the value that would appear on-screen, after your first expression:
=IIF(ReportItems!txtBelfast.Value = "N/A", "#faa1a1", "Black")

ssrs 2008 R2 rounding Fill expression value to match displayed percentage

I have a textbox which I need to colour format based on an expression.
Here is the value in the textbox:
=iif(Fields!TotalStartsForTurnaround.Value=0
,Fields!Within2Hours.Value/Fields!TotalStartsForTurnaround.Value)
The textbox is formatted to show the value as percentage with 0 decimal places.
I have the following fill colour criteria:
If value <90% then red
If value >=90% and <96% then Orange
if value >=96% then Green
The Fill expression is as follows:
=iif(Fields!TotalStartsForTurnaround.Value=0,"White"
,iif((Fields!Within2Hours.Value/Fields!TotalStartsForTurnaround.Value)<0.9
,"Red"
,iif((Fields!Within2Hours.Value/Fields!TotalStartsForTurnaround.Value)>=0.9
and (Fields!Within2Hours.Value/Fields!TotalStartsForTurnaround.Value)<0.96
,"Orange"
,"Green")))
However say I have a value of 0.89999. The colour of the textbox is correct but because the percentage is being rounded.. the display value is 90%.
How can I get the fill expression to match up with the rounding of the percentage so that colour coding matches the percentage displayed?
Simplifying your expression for clarity, instead of using something like:
=IIf(Fields!MyValue.Value < 0.9, "Green", "Red")
In your BackgroundColor expression, Round the value being checked in the same way it is rounded in the the formatting:
=IIf(Round(Fields!MyValue.Value, 1) < 0.9, "Green", "Red")
This should mean what the user is seeing and what is being used in the colour check should match up.
A couple of things that might help:
Add a calculated field to your Dataset to represent the result of Fields!Within2Hours.Value/Fields!TotalStartsForTurnaround.Value - this will be usable in subsequent report expressions and help make the code easier to follow.
Use a Switch expression to determine the colour instead of a series of nested IIf statements.

SSRS set font colour base on background colour

I am using SSRS on SQL Server 2008 R2, I have cell with dynamic background colour, how could I change font to black when background is white.
I have tried:
=iif (Fields!DATE.BackgroundColor = "White" , "Black", "White")
You'll need to set the two properties in two expression based on the same condition. Even if the Textbox is displaying a different field in its text, you can still use any fields in the same row in the property expression.
e.g. for BackgroundColor use something like:
=IIf(Fields!Date.Value < CDate("01-Jan-2013"), "Black", "White")
then for the Color property use something like:
=IIf(Fields!Date.Value < CDate("01-Jan-2013"), "White", "Black")
Here for dates prior to 01-Jan-2013, the Textbox will be black with white text, and for dates from this year, the Textbox will be white with black text.
Edit after comments
Just to confirm, there is no readily available way to check report items properties (other than Value) in SSRS expressions. I agree this would be nice but for now this is not an option.
So you need to use the same condition check for both the BackgroundColor and Color property expressions.
It sounds like you already have something set for BackgroundColor so it should be straightforward to apply an updated expression for Color where required.

In SSRS how to conditionally change the colour of a datalabel font on a chart when it appears on the bar

I have created a bar chart that shows values on data labels.
The Data label is placed outside the bar
But in some cases the label appears on the bar where the bar is too long.
In this scenario I would like to conditionally change the font/colour of the data label so that it's more visible.
However I can't see a way to dynamically determine where the label has been placed.
What I can think of is this. You can change the background/font color of all those series labels who's value lies in the range of 95%-100% of the maximum "Value". To be exactly precise as to what should be the threshold to change the bg/font color seems a daunting task, but you could play around with test data.
For writing the expression to change the font color,I would first change the dataset and add a column on the lines of PercOfMax. This column can be calculated easily in the dataset by using basic aggregate functions.
Then you need to go to the Chart Series Label properties-->Color and write the expression on the lines of -
=IIF(Fields!PercOfMax.Value>=95, "YELLOW", "BLACK")
As I said, you might need to do some more research to finalize the value of this threshold(which I am assuming to be 95).
Another solution to this problem is to use fill colour of the label and set its background to a bright colour (e.g. colour), and leave the font colour of the label black. Thus you can always see the label, and there is no difference when it's outside of the bar.