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.
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.
Choose the Occupation column as the group by option and click the OK button.
Let me show you the report preview.
Select the Details row, go to the Background Color property, and click the Expression 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")
And the final report is.
If you observe the report review, each group has two different or alternative background colors.
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.