How to Add Excel-like “color scale” red-yellow-green conditional formatting in SSRS report based on min and max values

你。 提交于 2020-01-06 18:09:42

问题


How can I create heat map in SSRS based on min and max values? Right now I'm using SWITCH function in order to differentiate colors.

    =
    SWITCH 
        (Fields!.Value = 0, "Coral",
            Fields!.Value >=1  and Fields!.Value <= 5 , "Yellow", 
            Fields!.Value >=6  and Fields!.Value <= 10 , "Gold", 
            Fields!.Value >= 11 and Fields!.Value <= 16,"#bdff30",
             Fields!.Value >= 17 and Fields!.Value <= 22,"#7fda24",
Fields!.Value >= 55 ,"#0ca102")

But how can I just tell SSRS that, for example between 5 different values, choose heat map colors, lets say shades from red to green and assign those colors to each value in a cell? Should be like this:


回答1:


I don't think you need to make code. I was thinking more about something like this :

 =SWITCH 
(Fields!.Value >= Min(Fields!myField.Value, "DataSetName") + (5 *((Max(Fields!myField.Value, "DataSetName")-Min(Fields!myField.Value, "DataSetName"))/6)) ,"#0ca102"
 Fields!.Value >= Min(Fields!myField.Value, "DataSetName") + (4 *((Max(Fields!myField.Value, "DataSetName")-Min(Fields!myField.Value, "DataSetName"))/6)) ,"#7fda24"
 Fields!.Value >= Min(Fields!myField.Value, "DataSetName") + (3 *((Max(Fields!myField.Value, "DataSetName")-Min(Fields!myField.Value, "DataSetName"))/6)),"#bdff30"
 Fields!.Value >= Min(Fields!myField.Value, "DataSetName") + (2 *((Max(Fields!myField.Value, "DataSetName")-Min(Fields!myField.Value, "DataSetName"))/6)),"Gold"
 Fields!.Value >= Min(Fields!myField.Value, "DataSetName") + ((Max(Fields!myField.Value, "DataSetName")-Min(Fields!myField.Value, "DataSetName"))/6),"Yellow"
 1=1,"Coral")

With values from 5 to 60 for exemple the test become :

     =SWITCH 
(Fields!.Value >= 50.83 ,"#0ca102"
 Fields!.Value >= 41.67,"#7fda24"
 Fields!.Value >= 32.5,"#bdff30"
 Fields!.Value >= 23.33,"Gold"
 Fields!.Value >= 14.17,"Yellow"
 1=1,"Coral")

I'm really not good in maths. There is maybe (definitely) better formulas... It's just to show what I would say ^^ Using percent to deduce ranges.




回答2:


For first : With the switch : it takes the first right value : so you don't need to write 2 conditions to test a value. Just take them from the biggest to the smallest. For exemple :

 =
SWITCH 
    (Fields!.Value >= 55 ,"#0ca102"
     Fields!.Value >= 17 ,"#7fda24"
     Fields!.Value >= 11,"#bdff30"
     Fields!.Value >= 6,"Gold"
     Fields!.Value >= 1,"Yellow"
     1=1,"Coral")

To get the max of the values it's possible : with the function "MAX" (and the same for MIN). Don't forget here to references all the dataset (in case of groups). So when you use the max for all the dataset it's like that :

=Max(Fields!myField.Value, "DataSetName")

You can then, make operations with min and max then to repace your fixed values. But I can't help you more for that because I'm really not good with maths.



来源:https://stackoverflow.com/questions/38861072/how-to-add-excel-like-color-scale-red-yellow-green-conditional-formatting-in-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!