none
How to count columns in SSRS.

    General discussion

  • I was stuck because there is no way to tell what column number you're on in SSRS, at least no way I could find. So I just wrote a little function that let's me know what column I'm in (in my case a column group). When i get to the max number of columns I reset for the next row.

    Thought it might be helpful for people out there:

     

    Public columnNumber As Integer = 0

    Public Function ColNumber(ByVal colNo, ByVal maxCols) AS Integer

    Dim retColNo As Integer

    columnNumber =columnNumber + colNo

    retColNo = columnNumber

    ' resets for next row
    If (columnNumber=maxCols) Then
      columnNumber=0
    End If

    return retColNo

    End Function

     

    Always call like this: =iif(Code.ColNumber(1, N)=Y, <do something>, <do something else>)

    N= Max number of columns in table (or which col index to stop counting at and reset)

    Y= which column number to check for

     

    Hope it helps.

     


    --ACG
    • Edited by ACG Friday, August 06, 2010 10:56 AM update
    Thursday, August 05, 2010 11:24 PM