Tuesday, December 20, 2005 - Posts

Dynamically Changing the Colors of a Value in Reporting Services

In Reporting Services you can dynamically alter the color of a font by clicking the drop-down box for a font color and selecting Expression. This works well, if you would like to show a red color if your not crossing certain price points and green if your numbers look good. The syntax to perform this type of action would look like this:

=IIF( Fields!ytd_profit.Value < 1,"red","green")

Essentially the above is a clasic IF THEN....ELSE statement. If the profit is less than $0, then turn the color red, otherwise keep it green. The problem comes if you want a third or fourth condition. In this type of situation, you'll need to use the SWITCH statement. This statement in Reporting Services performs the same type of activity as a CASE statement in VB. Here's an example of how you could use the same logic as before but show especially good profit as blue.

=Switch( Fields!profit.Value < 1,"red",
Fields!profit.Value > 0,
"Green",
Fields!profit.Value > 100, "blue")

-- Brian Knight