Change Colour of Textbox

Clive Wightman 121 Reputation points
2021-05-06T09:07:57.55+00:00

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.
=sum(iif(Fields!QUALITY_CHECK.value<>3,1,0))/(RowNumber("dst_PERFORMANCE"))

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,799 questions
0 comments No comments
{count} votes

Accepted answer
  1. Joyzhao-MSFT 15,566 Reputation points
    2021-05-07T02:21:51.867+00:00

    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.
    94540-01.jpg
    The expressions of Test1 and Test2 are only in different order.

    Let's look at Test3 again:
    94621-02.jpg
    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,
    Joy


    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]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html [3]: /api/attachments/94550-02.jpg?platform=QnA

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Olaf Helper 40,816 Reputation points
    2021-05-06T11:26:52.757+00:00

    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
    2021-05-06T20:10:37.017+00:00

    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

    --Dan

    0 comments No comments