Change Colour of Textbox

Clive Wightman 121 Reputation points

Hi I'm trying to set the colour of the textbox dependant on the percentage value within it.

I have tried
=SWITCH(ReportItems!Textbox37.Value <= "91", "Red", ReportItems!Textbox37.Value <= "70","Orange",ReportItems!Textbox37.Value <= "100","Green",True,"Blue")
But this just returns all results in RED. regardless of the percentage value.

The result is derived from the following expression.

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,726 questions
0 comments No comments
{count} votes

Accepted answer
  1. Joyzhao-MSFT 15,556 Reputation points

    Hi @Clive Wightman ,
    The SWITCH function evaluates one value (called the expression) against a list of values, and returns the result corresponding to the first matching value. If there is no match, an optional default value may be returned.
    I think it’s easier to understand by testing.
    The expressions of Test1 and Test2 are only in different order.

    Let's look at Test3 again:
    It is not difficult for us to discover the mystery.

    So I guess your expression should be changed to:

    =SWITCH(ReportItems!Textbox37.Value <= "70", "Red", ReportItems!Textbox37.Value <= "91","Orange",ReportItems!Textbox37.Value <= "100","Green")  

    Best Regards,

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our [documentation][3] to enable e-mail notifications if you want to receive the related email notification for this thread.

    [3]: [3]: /api/attachments/94550-02.jpg?platform=QnA

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Olaf Helper 38,706 Reputation points

    SWITCH returns the first as true evaluated expression; if all values are equal lower 91% then all get colored in red.
    Write the expression from lower to higher percents, add a lower figure when the colour should stay white und use numeric values, not strings; like

    =SWITCH(ReportItems!Textbox37.Value <= 60, "White",
            ReportItems!Textbox37.Value <= 70, "Orange"
            ReportItems!Textbox37.Value <= 91, "Red",
            ReportItems!Textbox37.Value <= 100,"Green")
    0 comments No comments

  2. DJAdan 671 Reputation points

    One other thought, and may be irrelevant, but if you really mean Percentages, make sure your units are not really between 0.0 and 1.0, i.e., 0.75 means 75%.

    This will cause your SWITCH statement logic to evaluate <=60 as TRUE for all values, when you intended it to evaluate <= 0.60


    0 comments No comments