question

CliveWightman-8621 avatar image
0 Votes"
CliveWightman-8621 asked Joyzhao-MSFT edited

Change Colour of Textbox

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Joyzhao-MSFT avatar image
0 Votes"
Joyzhao-MSFT answered Joyzhao-MSFT edited

Hi @CliveWightman-8621 ,
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 to enable e-mail notifications if you want to receive the related email notification for this thread.



01.jpg (84.1 KiB)
02.jpg (45.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered

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")


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DJAdan-4490 avatar image
0 Votes"
DJAdan-4490 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.