Monday, December 29, 2008

matrix RowNumber doesn't work with even rows

I recently ran into a new issue with Microsoft Reporting Services 2005 matrix control.
When trying to color alternating columns with collapsible row groups, I discovered that when a group contained an even number of rows the typical alternating code didn't work:
iif(RowNumber("matrix_RowGroup") Mod 2, "LightGrey", "White")

This is due to RowNumber being multiplied by the number of rows when a group is collapsed.

After some research and playing around I discovered that CountRows() would give me the number of rows in the current context, so when a group was expanded it would always return 1, while when the group was collapsed it would give me the number of rows in the group.  After that a little simple division worked wonders and fixed my issue:
iif(RowNumber("matrix_RowGroup")/CountRows() Mod 2, "LightGrey", "White")

No comments: