0
votes

I am using this for my alternating background colors

IIF((RowNumber(Nothing) Mod 2),"GAINSBORO", "WHITE")

before hidden row

but I need to hide one of my rows in the Tablix which then causes this to happen

after row hidden

What's the best way to continue the alternating color of rows with the hidden row?

2
How are you hiding the row in your table? Are you using a filter for it, or some other method to change the visibilty?Jonnus
I'm right clicking on the Tablix row and selecting Row visibility... then I added my expression to hide the row based on condition of the year parameter. When the year changes to 2015 the row becomes hidden and thus the alternating background colors get jacked up.TechGrl1
As a general comment it would be much more efficient to filter your table. Right click the tablix, select filtering, and year = 2005. Using this method your existing calculation should workJonnus
Tried the filter but I have nested Groups within the Tablix. messes up the data view.TechGrl1

2 Answers

1
votes

Based on this answer to another question I have another method for alternating the row colours, this time taking the hidden row into consideration.

You need to add the following Custom Code to the report

Dim CurrentColour As String
Dim LastRowNumber AS Integer

Function SwitchColour(ThisRowNumber As Integer) As String
    If CurrentColour = "" Then
        CurrentColour = "Red"
    End If

    If LastRowNumber = 0 Then
        LastRowNumber = ThisRowNumber
    End If

    If LastRowNumber <> ThisRowNumber Then
        ' Change the colour
         If CurrentColour = "Red" Then
            CurrentColour = "Yellow"
        Else 
            CurrentColour = "Red"
        End If
        LastRowNumber = ThisRowNumber 
    End If

    Return CurrentColour 
End Function

This is effectively saving a value for the CurrentColour to persist across the elements in the report. When the SwitchColour function is run it determines if the row number has changed (LastRowNumber <> ThisRowNumber), and if so changes the colour for the cells.

Using this sample data as “DataSet1”

Val | Colour
----+-------
36  | Red
22  | Red
55  | Green
23  | Red
74  | Red

And setting the cells BackgroundColour to

=Code.SwitchColour(RowNumber(“DataSet1”))

Give this result

enter image description here

When you then apply a visibility expression to the Row to negate the value “Green” for example using this expression

=iif(Fields!Colour.Value = "Green", True, False)

The result is like this

enter image description here

Note the colouring still changes, despite there being a record absent from the middle of the table

Is this the sort of behaviour you would like, and is it something you can apply to your project? If you need further assistance, please let me know.

0
votes

Have you seen this previous answer regarding alternating row colours?

You can use a combination of CountDistinct and RunningValue to calculate a row number in the background that you can then use to set the BackgroundColor property of your rows, assuming there is a unique value to each of the rows you are reporting on.

For example the following expression in the BackgroundColor property of the tablix row

=iif((RunningValue(CountDistinct(Fields!Serial.Value), Sum, "DataSet1") mod 2) = 0, "Tomato", "LimeGreen")

Sets this table to have alternating red and green rows.

enter image description here