The "green bar" effect is a document is the alternating of one background color (usually white) with another background color (originally light green) on each printed line of a document in order to make it easier to read across each line of text. The term comes from the days of impact printers with continuous feed paper that was pre-printed with just such a scheme of alternating colors, and it remains a popular method of making long lists, particularly grids, easy to read. Here is an example:
The method of formatting SQL Server Reporting Services tables with a "green bar" effect is not difficult. Formatting a matrix is only a little more difficult.
Formatting a Table
- In design mode, highlight all the text boxes in the (Details) section. Use a click-and-drag method to select them all in one step or hold down the Ctrl key and click each one in turn.
- On the Properties pane click the down-arrow for the value of the BackgroundColor property, and then click Expression...
- Enter the following expression. If you want colors other than white and light green, substitute your own color choices.
=IIf(RowNumber(Nothing) mod 2 = 0, "LightGreen", "White")
Formatting a Matrix
- Create your matrix, and then right-click on the left-most column and select Insert Column > Inside Group - Left.
- On the bottom-left text box of the matrix, which was just created when you added the new column, right-click and select Text Box Properties...
- Change the Name property to RowNumber.
- Enter the following expression as the Value property:
=RunningValue(Min(1), Sum, Nothing)
- Click OK to confirm the new settings for the text box.
- If you do not want the running count of rows to appear in your final matrix, click on the tablix column marker to select the entire column. Then use the Properties pane to change the Hidden property to True.
- Click on the text box that will show the aggregate data for your matrix (in an Excel PivotTable this would be called the "data region" cell).
- On the Properties pane click the drown-arrow for the value of the BackgroundColor property, and then click Expression...
- Enter the following expression.
=IIf(ReportItems!RowNumber.Value mod 2 = 0, "LightGreen", "White")
I love this! Great tip and explained very well. This makes for an attractive and useful grid that transports well to excel or wherever.
ReplyDeleteIs there a way to apply the "green bar" effect to only the visible rows? I have a condition on my detail line that is filtering out report conditions (which can't be filtered in the source SQL query), but I want to use the green bar effect on the results after the detail visibility is set. How could I perform that task? If I remove my visibility condition, the above works perfectly...but when some rows are hidden, it's a little wacky. Thanks.
ReplyDeleteThe problem is that the hidden rows, though taking up no space in the output, still "exist" as far as the tablix context is concerned. So the values affect sum totals and other aggregate functions, including RowNumber.
DeleteCan you remove the filter from the row visibility and add it to the tablix filter property? It might require some creative use of expressions, depending on the complexity of the filter condition, but it would then allow all the rows to be visible and render the green bar effect as desired.
I think I figured out a solution to filter the table using a very long iif condition so as not to use the report items. Thanks!!!
ReplyDelete