Alternating row color expression in SSRS matrix not working correctly

隐身守侯 提交于 2019-12-02 11:22:44

问题


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?

Edit-:Solution


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/35894822/alternating-row-color-expression-in-ssrs-matrix-not-working-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!