[英]SSRS Change Fill Colour Depending on Cell Values
I'm aware this has been asked a few times however I'm struggling to find an answer to what I need it for (Or maybe I have missed the answer so please feel free to copy and paste a link if has already been asked) 我知道这个问题已经被问过几次了,但是我一直在努力寻找我需要的答案(或者也许我错过了答案,所以如果已经被问到,请随时复制并粘贴链接)
I'm aware through searching on here the Switch
function can help change the colour of the background depending on the value. 我知道通过在此处搜索“ Switch
功能可以帮助根据值更改背景的颜色。 I have 3 colours needed, however one seems to over ride the other which is causing the issue, and I think this is because one value is in between two numbers 我需要3种颜色,但是一种似乎超出了另一种颜色,这导致了问题,我认为这是因为一个值介于两个数字之间
I'm trying to show 我想展示
Equal or greater than 10 - Red Equal to or greater than 5 until 9.99 - Amber Equal or greater than 0 until 4.99 Green Less than 0 until -4.99 Green -5 until -9.99 Amber -10 or greater Red 等于或大于10-红色等于或大于5直到9.99-琥珀色等于或大于0直到4.99绿色小于0直到-4.99绿色-5直到-9.99琥珀色-10或更大红色
I'm using this but it isn't working; 我正在使用它,但是它不起作用;
=switch(Fields!Field_Name <= -10, "Red",
Fields!Field_Name <= -5, "Amber",
Fields!Field_Name >= 10, "Red",
Fields!Field_Name >= 0, "Green",
Fields!Field_Name <= 4.99, "Green",
Fields!Field_Name < -0.1, "Green",
Fields!Field_Name <= -4.99, "Green",
Fields!Field_Name > 5, "Amber", True, "Green")
Any help (and not ridicule) would be really appreciated! 任何帮助(而不是嘲笑)将不胜感激!
Cheers 干杯
I find, sometimes it helps to draw out where you want the colours in a range. 我发现,有时可以帮助您确定想要的颜色范围。 Then work from outer most conditions inward. 然后从最外面的条件向内工作。
Here's an example of how I would test with a T-SQL CASE
expression. 这是我如何使用T-SQL CASE
表达式进行测试的示例。 I think this logic is what you're after. 我认为您所追求的是这种逻辑。 I've also included an example as an expression. 我还提供了一个示例作为表达式。
WITH
source_data
AS
(
SELECT tbl.* FROM (VALUES
( -11, 'Red')
, ( 11, 'Red')
, ( -6, 'DarkOrange')
, ( 6, 'DarkOrange')
, ( 1, 'Green')
, ( 4.98, 'Green')
, ( -0.11, 'Green')
) tbl ([Field_Name], [FillColourWanted])
)
SELECT
[Field_Name] = CAST([Field_Name] AS FLOAT)
, [FillColourWanted]
, [FillColour] =
CASE
WHEN [Field_Name] <= -10 OR [Field_Name] >= 10 THEN 'Red'
WHEN [Field_Name] <= -5 OR Field_Name >= 5 THEN 'DarkOrange'
WHEN [Field_Name] < 5 OR [Field_Name] > -5 THEN 'Green'
END
FROM
source_data
=Switch(
Fields!Field_Name.Value <= -10 OR Fields!Field_Name.Value >=10, "Red"
, Fields!Field_Name.Value <= -5 OR Fields!Field_Name.Value >= 5, "DarkOrange"
, Fields!Field_Name.Value > -5 OR Fields!Field_Name.Value < 5, "Green"
)
The background colour for [FillColourWanted]
and [FillColor]
are set by the values from the SQL columns. [FillColourWanted]
和[FillColor]
的背景色由SQL列中的值设置。 The background colour for [Expression]
is set by the expression example. [Expression]
的背景色由表达式示例设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.