Add Alternative Row Color to SSRS Report

In this article, we will show you how to add Alternative Row Color to SSRS Report. It is one of the Frequently asked questions by users. So, here, we will show you the step-by-step approach to adding Alternative Row Colors to SSRS Report using an Expression with an example.

We are going to use the below-shown DataSet to explain the same. Please refer to Embedded Data Source and Dataset articles to understand the steps involved in creating the Embedded Data Source and Dataset we used for this SSRS report.

DataSet

And the Custom SQL query that we used in the above Dataset is:

SELECT [FirstName] +  ' ' + [LastName] AS FullName
      ,[Education]
      ,[Occupation]
      ,[YearlyIncome]
      ,[Sales]
      ,[HireDate]
  FROM [Employee]

Data written by the above query is:

Source Table

How to add Alternative Row Color to SSRS Report

We are going to use the previously designed report, as we have shown below. Please refer to the TableFormat Table article to understand the steps involved in creating Table & format. Next, visit the headers and Footer article for adding Page headers and footers.

Sample Table to add Alternative Row Color to SSRS Report 2

Let me show you the Preview.

Table Preview 3

When you select the details row, you have an option called Background color in the properties pane. You can use all the predefined ones if you want to make the standard color for all the records returned by the report.

Add Alternative Row Color to SSRS Report

Here our task is to add alternate row color to SSRS Report. It means we have to use some conditions to check for alternating rows.

To do so, Please click on the Expression hyperlink under the Background Color property.

Add Alternative Row Color to a SSRS Report 4

Once you click on the Expression hyperlink, a new window called Expression will open. Use this expression window to find them.

Add Alternative Row Color to a SSRS Report Expression 5

Within the Expression, we are going to use the IIF condition to check whether the row number is even or not. If it is even, Pale Turquoise, otherwise Plum. By this, we can add alternative row colors to the SSRS report.

=IIF(RowNumber(Nothing) MOD 2 = 0, "PaleTurquoise", "Plum")
Expression for alternative background color to a SSRS report 6

Once completed, Click OK to close the window.

Add Alternative Row Color to a SSRS Report 7

As you can see that our report preview is displaying the specified colors as the alternate row color in SSRS Report

Add Alternative Row Color to SSRS Report 8

Add Alternative Background Colors to SSRS Table Group Rows

This SSRS article shows how to change the alternative background colors of a table group rows using the IIF condition or expression. It displays color based on the group.

Right-Click on the Datasets folder to create a new DataSet. The below screenshot shows the data set that we use for this example.

DataSet

The Sql query that we used above SSRS example is:

SELECT [FirstName] +  ' ' + [LastName] AS FullName
      ,[Education]
      ,[Occupation]
      ,[YearlyIncome]
      ,[Sales]
      ,[HireDate]
  FROM [Employee]

We have designed a simple table report of Employees and formatted the font and colors.

Add Alternative Background Colors to SSRS Table Group Rows

Under the Row group section, click the down arrow beside the details and select add group and parent group.

Add Parent Group to a Table Report

Choose the Occupation column as the group by option and click the OK button.

Choose the Group By Column

Let me show you the report preview.

Report Preview

Select the Details row, go to the Background Color property, and click the Expression hyperlink.

Click the Background Color Hyperlink

The below iif statement uses the RunningVlaue function, which assigns a unique number to each group. Next, we used the MOD function to find the remainder. If the remainder is zero, it is an even group, so assign Pale Turquoise color. Otherwise, Plum color.

=IIF(RunningValue(Fields!Occupation.Value, CountDistinct, "DataSet1") MOD 2 = 0, "PaleTurquoise", "Plum")
Expression to Add Alternative Background Colors to SSRS Table Group Rows

And the final report is.

Final Table

If you observe the report review, each group has two different or alternative background colors.

Preview the Add Alternative Background Colors to SSRS Table Group Rows

Let me change the Add Alternative Background Colors to SSRS Table Group rows expression to the below one.

=IIF(RunningValue(Fields!Occupation.Value, CountDistinct, "DataSet1") MOD 2 = 1, "PaleTurquoise", "Plum")

Preview the report.

Add Alternative Background Colors to SSRS Table Group Rows Preview