Search code examples
sqlreporting-servicesssrs-2008ssrs-2008-r2

Alternating row color expression in SSRS matrix not working correctly


In the only row group I am trying to get a alternate row color with the following expression:

Expression for background color : =IIf( RunningValue (Fields!SP.Value, CountDistinct, Nothing) MOD 2, "White", "blue")

SQL code: 

select
ROW_NUMBER() OVER (ORDER BY DataDate) AS SSRSRowNumber
,datepart(dw,datadate) SSRSDateFilter 
,DataDate
,SP
,sum(TMI) as TotalCI
from table
where DataDate>GETDATE()-20
group by DataDate,SP
order by 1, 2

The result is the picture below, what's wrong in the expression listed above?

Example of problem

Edit-:Solution


Solution

  • The missing dates in your data is causing the issues with the background row color not working correctly.

    You can waste lots of time trying to make your query work.

    Or you could just use the Alternating Row Color function.

    Private bOddRow As Boolean
    '*************************************************************************
    ' -- Display green-bar type color banding in detail rows
    ' -- Call from BackGroundColor property of all detail row textboxes
    ' -- Set Toggle True for first item, False for others.
    '*************************************************************************
    Function AlternateColor(ByVal OddColor As String, _
             ByVal EvenColor As String, ByVal Toggle As Boolean) As String
        If Toggle Then bOddRow = Not bOddRow
        If bOddRow Then
            Return OddColor
        Else
            Return EvenColor
        End If
    End Function
    

    For the first column that controls the color:

    =Code.AlternateColor("AliceBlue", "White", True)
    

    For the remaining columns, don't toggle with the third argument:

    =Code.AlternateColor("AliceBlue", "White", False)
    

    You may need to switch the colors in the first column in a matrix.

    SSRS Alternating row color issues when some rows are not visible