In this post we will discuss changing the format of report items or properties based on the data in the report. We will show how build conditional expressions. For example: changing a row background color based on a field value.
To make styles conditional, we’ll an expression instead of a static value for the style properties of the item. At run time, the report processor evaluates the expression and substitutes the result for the property value, just as if you had set the property to a static value at design time. When the report is rendered, the run-time value is used.
We are using the report "SalesByFiscalYear" which we had created previously in the Introduction to Report Builder 3.0 Part 2 - Creating a Report post.
Changing Font Color
To make the font color of a textbox render values in red for a field called FullName, open the Properties pane and use the following expression in the Font >> Color property:
=Switch(Fields!FullName.Value = "Jillian Carson", "Red", Fields!FullName.Value ="Rachel B Valdez", "Red", Len(Fields!FullName.Value) > 0, "#4c68a2")
Note: You can consider using a IIF statement to accomplish the same result.
Alternating Row Color
To alternate the background color for every other row in your table, set the BackgroundColor property for each textbox in the row to the same conditional expression.
Note: This method works for detail rows only in a table with no groups.
=IIF(RowNumber(Nothing) MOD 2, "Khaki", "White")
Run the report. Select all in the dropdown list and view report. Expand Northwest and you should see a simliar view: