SSRS – Change the background Row color when a value in the row differs from the corresponding value in the previous row

Problem – I want the background color of a row to change each time a value changes from row to row – this will help visually group the data
Answer

Create some custom code

Private _dateCount As Integer = 0
Private CurRowNumber as Integer = 0
Private ColorValue as String = “”

Function GetDateRowColor(ByVal previousVal As String, ByVal currentVal As String, MyRowNumber as Integer) As String

‘Check if this is a new row number…
If MyRowNumber <> CurRowNumber then
CurRowNumber = CurRowNumber + 1 ‘New row, so increment counter

If previousVal = currentVal Then
‘ Do nothing
Else
_dateCount = _dateCount + 1
End If

If _dateCount Mod 2 = 0 Then
ColorValue = “White”
Else
ColorValue = “Lavender”
End If
End If

Return ColorValue ‘Always return a value (for columns other than the first one)

End Function
Call the code in the row background setting property

=Code.GetDateRowColor(Previous(Fields!field_name.Value), Fields!field_name.Value, RowNumber(Nothing))

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: