Alternating Row Background Color within a Group

posted on Thursday, July 06, 2006 10:35 AM by kfinley

A typical report enhancement is to provide alternating row background colors for a table within Reporting Services. This is pretty easy if you have a simple table with no groupings. Just use the following expression in the row BackGroundColor property:

= IIF(RowNumber(Nothing) Mod 2, "Gainsboro", "White")

This becomes a little more tricky when you have groupings involved. But thanks to Chris Hays and his Reporting Services Sleazy Hacks I found how to do alternating row colors at the group level. Use this expression for the details row within a group:

= IIF(RunningValue(Fields!Some_Field.Value, CountDistinct, "Group_Name") Mod 2, "Gainsboro", "White")

For this you need to use the field you are grouping the details row on and for "Group_Name" use the parent group for that details section. I'm sure this can be done with multiple groups in a table but I haven't tried it yet.

Good luck and happy Reporting Services Hacking! :)

Now Playing: Ultimate Fakebook - Open Up And Say Awesome - When I'm With You I'm OK

re: Alternating Row Background Color within a Group

Saturday, May 12, 2007 3:20 PM by Ozren
The solution will not work in all cases. The reason is that you need row number to do that and Count will give you that, not CountDistinct. So, use:
= IIF(RunningValue(Fields!Some_Field.Value, Count, "Group_Name") Mod 2, "Gainsboro", "White")

re: Alternating Row Background Color within a Group

Thursday, May 21, 2009 7:41 AM by Dave
I use a simpler version:

=IIf(RunningValue(1, Sum, "Group_Name") Mod 2, "White", "WhiteSmoke")

re: Alternating Row Background Color within a Group

Wednesday, April 21, 2010 11:53 PM by JotGe
Best solution is described here:
http://www.wrox.com/WileyCDA/Section/Report-Solution-Patterns-and-Recipes-Greenbar-Reports.id-291857.html
This works also with tables.

re: Alternating Row Background Color within a Group

Thursday, October 06, 2011 10:54 AM by Peggy
Right on-this hlpeed me sort things right out.