Search code examples
visual-studioreporting-servicesssrs-2008

Switch cell fill color in SSRS report


I'm teaching myself SSRS, and I've built a report that I would like to use. Each product has it's own page, with a table of specifications.

The cell fill colors of the report will vary depending on the category of product (white grapes, red grapes, black grapes.)

Rather than create a seperate report for each category, I would like to change the fill colors depending on the category. Below is my code, but it's generating an error. I based this on another answer in stack overflow (Fill color based on values from other data set in SSRS)

=switch(
    (
        Fields!new_type.Value.Equals("White")
    ),  #749b53
    ,(
        Fields!new_type.Value.Equals("Red")
    ), #9D2347
    ,(
        Fields!new_type.Value.Equals("Black")
        #3D234f
    )

This is the error I'm getting: "The BackgroundColor expression for the text box 'new_arraname' contains an error: [BC31085] Date constant is not valid.


Solution

  • Try this, you are missing a comma and bracket.

    =switch(
        Fields!new_type.Value="White","#749b53",
        Fields!new_type.Value="Red","#9D2347",
        Fields!new_type.Value="Black","#3D234f"
        )