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
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.
For the first column that controls the color:
For the remaining columns, don't toggle with the third argument:
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
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 yourcross 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.