SSRS Color coding

  • I have to color code values in SSRS reports which are baed on another values for eg a statetotal value should be color coded depending on value of comparative performance value for the state. Can it be done? Has anyone done like this ?

    State total comparativeperformance

    MH 2.8% 1

    CT -1.2% 3

    AZ 0,1% 2

    The 2.8% should be colored as Green (1)

    The -1.2% should be colored as Red (3)

    The -0.1% should be colored as yellow (2)

  • Sure you can do this. You would put an expression in the color property (if you want the text to change colors) or the background color property for the object you want to change. It would be something like this:

    switch(Fields!total comparative.Value > 0, "green",

    Fields!total comparative.Value -1, "yellow",

    "Red")

  • Thanks Jack.

    The switch function offers to have multiple option for colors

    However you can apply on the field only in whose property we have attached the code

    I want to color one field depending on the value of another field

    Is it possible ?

  • Yes you can do the same thing just substitute the field you want to use for the field that I have provided. AS long a sit is the same dataset and scope you are fine.

  • Thanks

    Am able to do it

  • I am using Function in Report properties->Code to defined the colors and passing the value to this function.

    However if i had to control the colors depending on numeric values ( in decimals) the follwoing function does not allow it. Any idea?

    For eg

    if i want to control color if status in between -0.5 to +0.5 color = Yellow

    it does not allow?

    If i change the GetColor(ByVal status as string) as string from string to int or numeric it gives error,

    Any idea why ?

    Public Function GetColor(ByVal status as string) as string

    IF status <0 Then

    Return "Red"

    End IF

    IF status > 0 Then

    Return "Green"

    End IF

    IF status like "0" Then

    Return "Yellow"

    End IF

    End Function

  • ashish.chaudhari (1/29/2009)


    I am using Function in Report properties->Code to defined the colors and passing the value to this function.

    However if i had to control the colors depending on numeric values ( in decimals) the follwoing function does not allow it. Any idea?

    For eg

    if i want to control color if status in between -0.5 to +0.5 color = Yellow

    it does not allow?

    If i change the GetColor(ByVal status as string) as string from string to int or numeric it gives error,

    Any idea why ?

    Public Function GetColor(ByVal status as string) as string

    IF status <0 Then

    Return "Red"

    End IF

    IF status > 0 Then

    Return "Green"

    End IF

    IF status like "0" Then

    Return "Yellow"

    End IF

    End Function

    Ashish,

    Just try to use datatype Object instead of String and Decimal.

    E.g.

    Public Function GetColor(ByVal status as Object) as string

    IF status < 0 Then

    Return "Red"

    ElseIF status = 0 Then

    Return "Yellow"

    Else

    Return "Green"

    End IF

    End Function

  • Try this

    Select the Textbox required

    Click F4 to open properties window

    In BackgroundColor click on expression

    Enter

    =IIF(Fields!Total.Value = 2.8, "Green", IIF(Fields!Total.Value = -1.2, "Red", IIF(Fields!Total.Value = -0.1, "Yellow", "")))

    Click on Ok

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply