SSRS – Alternate Row Colors of A Group

SSRS – Alternate Row Colors of A Group

This has always been a challenge in Reporting Services – you’ve tried using this standard alternate row shading for a group but the alternation doesn’t work as expected:

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

For a Tablix Group, do the following:

  • Click Report >> Report Properties (or right click outside the bounds of your report within Design view and select Report Properties)
  • Click the Code tab and enter this custom function:
Public _evenRow As Boolean
Public Function EvenRow() As Boolean
_evenRow = Not _evenRow
return _evenRow
End Function

  • Right click your Tablix Row Group and select Row Group >> Group Properties.
  • Click the Variables tab and Add a new group variable.
    • Name: EvenRow
    • Value: =Code.EvenRow()
  • Now, instead of using the standard IIF(RowNumber… expression for the background color, use this expression for the background color of the row:
=IIF(Variables!EvenRow.Value=TRUE,"WhiteSmoke","White")

As far as I know, the moment you sort your group by an aggregate [Count(id)] the method fails. Otherwise, works great!

I am still trying to figure out how to get around this.

Mike250

I'm an Australian Chief Analytics Officer passionate about data science, visual insights, and all things sport—particularly cricket. An adventurer at heart, I’ve gone from abseiling cliffs to snorkeling in crystal-clear waters, sleeping in the wilds of Africa, and exploring destinations worldwide, with my latest trip taking me to Bali. When I'm not diving into data or analytics, I'm spending time with my three sons and two daughters, attempting to hit sixes for my local cricket club, reviewing chicken schnitzels or honing my craft around a coffee machine.

Related Posts
Leave a comment

Your email address will not be published. Required fields are marked *