Alternate row background colour in Reporting Services

This is just a note for me as it took a while to find on the net and even then it was confusing as to why it works but it does. Not sure whether you call this an MDX Query or part of a Transact-SQL mashup. You need to go to "Fill" (of each text box in the row - unless there's a faster way) and instead of color, click on the expression button (fx) and use the following:

copyraw
=IIF(RowNumber(Nothing) Mod 2, "#ffffff", "#eeeeee")

or 

=IIF(RowNumber(Nothing) Mod 2, "WhiteSmoke", "Garamond")
  1.  =IIF(RowNumber(Nothing) Mod 2, "#ffffff", "#eeeeee") 
  2.   
  3.  or 
  4.   
  5.  =IIF(RowNumber(Nothing) Mod 2, "WhiteSmoke", "Garamond") 

This is telling the report to be white (=#ffffff) in row 1 (odd row numbers) and a very light grey (=#eeeeee) in row 2 (even row numbers). The first row being of all rows in the dataset and not for a particular drill-down item. It will alternate between the two for the rest of the report. [The second example is what I use most frequently].

Additional:
Suppose you have lots of columns, you don't want to have to click on each cell to specify this so just do it to the first column then bring up the properties pane and scroll down to the "Fill > BackgroundColor" row and copy the value to your clipboard or notepad, etc. Then select all the remaining cells in the row and paste your expression in the "Fill > BackgroundColor" properties row... Done!

Borders:
I'm putting this here because often enough, if I'm going to make the report pretty with alternating rows, I'm probably going to look at the cell borders as well. I want a bigger border at the bottom of the overall report and a light one to divide each record. Staying within the properties pane, you can do the following:

copyraw
BorderColor:
#efefef, , , White, =IIF(RowNumber(Nothing)=Count(Fields!Field1.Value, "DataSet1"), "Black", "LightGray")

BorderStyle:
None, , , Solid, =IIF(RowNumber(Nothing)=Count(Fields!Field1.Value, "DataSet1"), "Double", "Solid")

BorderWidth:
1pt, , , , =IIF(RowNumber(Nothing)=Count(Fields!Field1.Value, "DataSet1"), "3pt", "1pt")

-- where "Field1" is a column in my dataset and "DataSet1" is my dataset
-- and Count(Fields!Field1.Value, "DataSet1") returns the maximum number of rows retrieved
  1.  BorderColor: 
  2.  #efefef, , , White, =IIF(RowNumber(Nothing)=Count(Fields!Field1.Value, "DataSet1"), "Black", "LightGray") 
  3.   
  4.  BorderStyle: 
  5.  None, , , Solid, =IIF(RowNumber(Nothing)=Count(Fields!Field1.Value, "DataSet1"), "Double", "Solid") 
  6.   
  7.  BorderWidth: 
  8.  1pt, , , , =IIF(RowNumber(Nothing)=Count(Fields!Field1.Value, "DataSet1"), "3pt", "1pt") 
  9.   
  10.  -- where "Field1" is a column in my dataset and "DataSet1" is my dataset 
  11.  -- and Count(Fields!Field1.Value, "DataSet1") returns the maximum number of rows retrieved 

Yields something like:
This is the bottom left of a report where both the above examples (fill and borders) have been applied:

Pretty unnecessary
Category: SQL Server Reporting Services :: Article: 320

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.