Alternating row color expression in SSRS matrix no

2020-04-20 08:09发布

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

2条回答
再贱就再见
2楼-- · 2020-04-20 08:25

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

查看更多
Luminary・发光体
3楼-- · 2020-04-20 08:35

This has occurred for me where I don't have an intersection between my row groups and column groups.

Example: - I have stored procedures 1 and 2

  • On 1/1, both 1 and 2 ran, so I record them

  • On 1/2, only 1 need to run, so I only record 1

  • On 1/3, they both ran again, so I recorded both

I'm going to have a messed up looking cell on 1/2 for sp 2 (the color won't change) because SSRS can't calculate a new value for the running total (it's still 1). On 3, it recognizes a value and gets that the running value is now 3, so coloring resumes as expected.

To solve this, you could perform a cross apply to get the cartesian product of all dates and SPs so that every distinct date has a row for every distinct date and store this in a temp table. Store your current query in a temp table or CSV and join onto your cross apply based query. This will ensure no missed cells. Note, this will have a performance impact so test accordingly (it is most likely negligible).

Let me know if you need help writing the queries.

查看更多
登录 后发表回答