Setting Color on a table's Field

  • I am trying to set the color to 'Green' if 5% or below, 'Yellow' Over 5% to 10%, else red.

    switch((Fields!Neg_Total_Count.Value/Fields!Total_Count.Value*100) <= 5, "Lime", (Fields!Neg_Total_Count.Value/Fields!Total_Count.Value*100) <= 10, "Yellow", "Red" )

    When I place the above code into the 'Appearance' 'BackgroundColor' Properity, I get an error that the above code is not a valid color.

    What am I doing wrong? Also is my code correct for Yellow and Red?

  • You are missing a value in your switch statement. Try this,

    switch((Fields!Neg_Total_Count.Value/Fields!Total_Count.Value*100) <= 5, "Lime",

    (Fields!Neg_Total_Count.Value/Fields!Total_Count.Value*100) <= 10, "Yellow",

    (Fields!Neg_Total_Count.Value/Fields!Total_Count.Value*100) > 10, "Red" )

    ______________________________________________________________________________________________
    Forum posting etiquette.[/url] Get your answers faster.

  • Calvo's suggestion should work.

    Switch does not have a functional ELSE, it is always boolean expression, value, boolean expression, value, boolean expression, value and so on. The switch statement will always return the first value for the boolean expression that evaluates to true.

    If you really want an Else type function because the switch evaluations don't neatly line up in numerical order a slight mod to Calvo's suggestion would more or less create the functional else.

    switch((Fields!Neg_Total_Count.Value/Fields!Total_Count.Value*100) <= 5, "Lime",

    (Fields!Neg_Total_Count.Value/Fields!Total_Count.Value*100) <= 10, "Yellow",

    1 = 1, "Red" )

    Since 1 = 1 will always evaluate to true, anything that does not meet the preceeding criteria will be red.

  • Hey, thanks for the help.. yep that works. I wish it had given me a better error message.. so that I had known it was not like a case statement.. where you can catch all events that did not match... Oh, well know better now! 😎

Viewing 4 posts - 1 through 3 (of 3 total)

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