Wednesday, June 25, 2014

SQL Server Reporting Services- Coloring a Cell Background Based on two different column group values

Hi AJ Hameed,


According to your description, you want to set the background color for the cells based on the values inside of cells and the values the column group. You want to set grey for cells on Friday and Saturday, set colors based on the task name on other weekdays. Right?


In Reporting Services, there's no problem if we have two different data values in conditional expression, so we can set background color based on Day_Wise or task_name. One issue in this scenario is, we can't have value "S" for both Saturday and Sunday when working in a matrix. Otherwise the task_name will overwrite the previous task_name (for numeric values, it will do sum calculation). So we suggest you change the values for weekdays in database. The expression you have posted was correct. It only has a small issue: the "Light Blue(Aqua)" also contains "Blue", so when doing conditional judging, the expression will return "Blue" instead of "Light Blue". We have tested in our local environment. For viewing convenience, we used the Switch() function in our expression:


=IIf(Fields!Day_Wise.Value="Fri" or Fields!Day_Wise.Value="Sat","LightGrey",

Switch(

InStr(Fields!Task_name.Value,"White")>0,"White",

InStr(Fields!Task_name.Value,"||")>0,"Maroon",

InStr(Fields!Task_name.Value,"Pink")>0,"Pink",

InStr(Fields!Task_name.Value,"Red")>0,"Red",

InStr(Fields!Task_name.Value,"Purple")>0,"Purple",

InStr(Fields!Task_name.Value,"Green")>0,"Green",

InStr(Fields!Task_name.Value,"Cyan(Teal)")>0,"Teal",

Fields!Task_name.Value="","White",

InStr(Fields!Task_name.Value,"Olive")>0,"Olive",

InStr(Fields!Task_name.Value,"Blue")>0,"Blue",

InStr(Fields!Task_name.Value,"Aqua")>0,"LightBlue",

InStr(Fields!Task_name.Value,"Yellow")>0,"Yellow",

InStr(Fields!Task_name.Value,"Orange")>0,"Orange",

InStr(Fields!Task_name.Value,"Null")>0,"Sienna",

true,"Black"

)

)


The result looks like below:


Reference:

Matrices (Report Builder and SSRS)


If you have any question, please feel free to ask.


Best Regards,

Simon Hou


No comments:

Post a Comment