SQL SSRS 在组内交替行颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24011213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SSRS Alternating Row Colour Within Groups
提问by Liam Domingo
I have a ssrs table report with row grouping and I would like to know how to change the colours of rows in groups without changing the background colour of the group column itself. With the answers I have found and implemented I get the effect of the second table in the picture when I want the effect of the first table:
我有一个带有行分组的 ssrs 表报告,我想知道如何在不更改组列本身的背景颜色的情况下更改组中行的颜色。根据我找到并实现的答案,当我想要第一个表格的效果时,我得到了图片中第二个表格的效果:
Any help will be much appreciated.
任何帮助都感激不尽。
This is a picture of the actual report and it's grouping:
这是实际报告的图片及其分组:
回答by Mike Honey
The RowNumber technique only works on the Details group i.e. the lowest level group (with no Group columns defined). Think of it as returning the Row in the Dataset.
RowNumber 技术仅适用于 Details 组,即最低级别的组(未定义组列)。将其视为返回数据集中的行。
Instead I would write an expression that calculates the equivalent to RowNumber, but for the Group level - typically something using RunningValue ... CountDistinct
on the Group Key field, like this:
相反,我会编写一个表达式来计算等效于 RowNumber,但对于组级别 - 通常RunningValue ... CountDistinct
在组键字段上使用的东西,如下所示:
= Iif ( RunningValue ( Fields!tableid.Value , CountDistinct , "TheNameOfYourGroup") Mod 2 = 0, "White", "WhiteSmoke")
= Iif ( RunningValue ( Fields!tableid.Value , CountDistinct , "TheNameOfYourGroup") Mod 2 = 0, "White", "WhiteSmoke")
回答by declandata
I need to apply the alternation to all rows including Total rows so:
我需要将交替应用于所有行,包括总行数,因此:
'define Report Variables: ActiveRowColour, ColourA, ColourB
'Call this function in one cell per row by setting => BackgroundColor=Code.NewActiveRowColour(Variables!ActiveRowColour.Value)
'Then All other cells on that row set -> BackgroundColor=Variables!ActiveRowColour.Value
Public Function NewActiveRowColour(ByVal sActiveRowColour As String) As String
If sActiveRowColour = Report.Variables!ColourA.Value Then
Report.Variables!ActiveRowColour.Value = Report.Variables!ColourB.Value
Return Report.Variables!ColourB.Value
Else
Report.Variables!ActiveRowColour.Value = Report.Variables!ColourA.Value
Return Report.Variables!ColourA.Value
End If
End Function