【问题标题】:How to implement Excel-like Conditional formatting and “color scale” in SSRS report如何在 SSRS 报告中实现类似 Excel 的条件格式和“色标”
【发布时间】:2020-05-11 01:31:16
【问题描述】:

我在 SSRS 中有一个如下表

 category 2018 percentage 2019 percentage
  c1      55    17%       7     11%      
  c2      0      0%       20     25%
  c3      6      2%       1      1%
  c4      26     8%       5     11%
  c5      4      1%       2      4%
  c6      10     3%       6      8%

我想在 SSRS 报告中实现带有色阶的条件格式等 excel,并希望为 2018 列和 2019 列中的前 3 个数字填充(背景颜色)。排序顺序应保持在类别中。
这意味着,我需要为 2018 年的 55,26 和 10 以及 2019 年的列中的 20,6 和 7 填充背景颜色。 我怎样才能做到这一点?

【问题讨论】:

    标签: reporting-services


    【解决方案1】:

    假设您的数据与 CTE 中的数据类似,您可以使用排名函数按年份分区并按实际值排序,以计算出每年的排名(就像您提到的那样.. 年度前 3 )。

    然后根据排名数字..为其分配颜色,然后使用该颜色值作为背景颜色

    示例代码:

      ;with mycte as (
    
      select
      'c1' as category ,55 as cat_value,'17%' as cat_percentage,2018 as cat_year
      union all
        select
      'c2',0,'0%',2018
      union all
        select
      'c3',6,'2%',2018
      union all
        select
      'c4',26,'8%',2018
      union all
        select
      'c5',4,'1%',2018
      union all
        select
      'c6',10,'3%',2018
      union all
        select
      'c1',7,'11%',2019
      union all
        select
      'c2',20,'25%',2019
      union all
        select
      'c3',1,'1%',2019
      union all
        select
      'c4',5,'11%',2019
      union all
        select
      'c5',2,'4%',2019
      union all
        select
      'c6',6,'8%',2019
     )
     ,rankings as (
     select 
     mycte.*
    
     ,RANK() over (partition by cat_year order by cat_value desc) as rank_value
    
     from mycte
     )
    
     Select *
     ,case when rank_value = 1 then 'Red'
     when rank_value = 2 then 'Blue'
     when rank_value = 3 then 'Green'
     else 'white' end as back_color
     from rankings
    

    然后在您的报告中,选择具有您想要着色的值的单元格..将该单元格的背景颜色设置为:

    =fields!back_color.value
    

    【讨论】:

    • 感谢 Haryy 的回复,但我无法合并年份列,因为它会更改报告格式。我们可以在不改变格式的情况下添加颜色列吗?
    • 我在 CTE 中添加了额外的列,可以实现我需要的。非常感谢 。您的回复有帮助
    • 如果它回答了你的问题..请接受我的回答
    猜你喜欢
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多