SSRS Alternating colors in groups

3k views Asked by At

I have tried all the expresssions posted for alternating colors in a group but it's not working correctly.

Here is what my report design looks like: enter image description here

I would like each group row to alternate colors and I would like the detail inside each group to alternate. However, I always get this for the group alternating

enter image description here

I am using this expression:

=IIF(RunningValue(Fields!AssignedUnit.Value,COUNT,NOTHING) MOD 2 = 0
,IIF(ROWNUMBER(NOTHING) MOD 2=0,"LIGHTBLUE","SILVER")
,IIF(ROWNUMBER(NOTHING) MOD 2=1,"SILVER","LIGHTBLUE"))

for the group fill and this expression for the detail fill:

= IIf(RowNumber(Nothing) Mod 2 = 0, "LIGHTBLUE", "SILVER")

enter image description here

can someone help me figure out what I need to change so that the outside groups alternate correctly?

Thank you.

2

There are 2 answers

2
Hannover Fist On BEST ANSWER

I use a function to control the background color - it's more reliable than using the ROWNUMBER function in SSRS.

You would add this to the VB Code section (Report Properties --> Code tab):

Private bOddRow(10) As Boolean 

Function AlternateColor(ByVal OddColor As String, ByVal EvenColor As String, ByVal Toggle As Boolean, ByVal Type AS INTEGER) As String 

  If Toggle Then bOddRow(Type) = Not bOddRow(Type) 

  If bOddRow(Type) Then 
                Return OddColor 
  Else 
                Return EvenColor 
  End If 

End Function

Then call the function from the BackgroundColor value:

=code.AlternateColor("AliceBlue", "White", 1, 1)

All the function does is check the bOddRow variable and return the first or second color depending on bOddRow's value.

The third argument is the Toggle value. If it is 1, the color will change otherwise it would return the same color. The first column in a group would toggle while the others would have a 0 so the color is the same as the first.

The fourth argument is for the group number. For your report, I would make the inner Group 1 for the last number and the outer group would be 2.

Inner Group First column background color :

=code.AlternateColor("AliceBlue", "White", 1, 1)

Inner Group Other columns background color :

=code.AlternateColor("AliceBlue", "White", 0, 1)

Outer Group First column background color :

=code.AlternateColor("MintCream", "WhiteSmoke", 1, 2)

Outer Group Other columns background color :

=code.AlternateColor("MintCream", "WhiteSmoke", 0, 2)

Plagiarized from my previous post: How to create Alternative Row Background colors in SSRS for values in a group

0
Golden Lion On

In my case I have an item for a row and my columns were year_month. I wanted to alternate fill color on the column.

    =iif(RunningValue(Fields!YearMonth.Value,CountDistinct,Nothing) Mod 2, "PaleTurquoise", "Plum")