Search code examples
sqlssrs-2008

Serial Numbering an SSRS Table with Grouping And Headers


[Report Design]

enter image description here

Here is an Example for a report that I am working on. It is grouped by "CostCenter" Field and above each group there is a header with the SUM of the "Betrag" Field. I want to Number each Column in the Table with the Headers as well. I tried using RowNumber(Nothing) or Row Number("DataSet") Or Running Value.

I get these results [Report View]

enter image description here

I think there should be a way or a Formula that connects both Fields in the Colmun Row Number or "Zeilennr" that results with a Correct Row Numbering for each Row


Solution

  • You can almost do this. The number would not work if placed to the left of the inner group, it needs to be at the same level as the details group but it will give you the correct number. I've only done very limited testing but it seems to work.

    Go to the report's properties and then to the code tab.

    Now add the following custom code function

    Public rn as Integer
    
    Public Function GetRn() AS Integer
        rn = rn +1
        return rn
    End Function
    

    Now in the text box where you want the number to appear use the expression

    =Code.GetRn

    All this does in increment the public variable by 1 then return it. It has no concept of the row it lies on, so if you did not include this on a group row, the numbers would remain sequential.

    Here is a demo based on a small test report I had..

    Design showing the position of the expression

    Gives this result

    enter image description here

    Add the same expression to more text boxes...

    enter image description here

    Give these results...

    enter image description here