SSRS code variable resetting on new page

前端 未结 3 1834
南方客
南方客 2021-01-05 03:24

In SSRS 2008 I am trying to maintain a SUM of SUMs on a group using custom Code. The reason is that I have a table of data, grouped and returning SUMs of the data. I have

3条回答
  •  一整个雨季
    2021-01-05 03:27

    Just changing the variables to shared won't work. If you set them to shared they'll be DOUBLED when you export to PDF / XLS / etc (because it just kept adding to the existing var). You have to do something like this:

    Public Shared Dim grandTotal as Decimal
    Public Shared Dim costCenterTotal as Decimal
    Public Shared Dim workerTotal as Decimal
    
    Public Shared Function Initialize() 
        grandTotal = 0
        costCenterTotal = 0
        workerTotal = 0
    End Function
    
    Public Function AddTotal(ByVal b AS Decimal) AS Decimal
        grandTotal = grandTotal + b
        costCenterTotal = costCenterTotal + b
        workerTotal = workerTotal  + b
        return b
    End Function
    
    Public Function GetWorkerTotal()
        Dim ret as Decimal = workerTotal
        workerTotal = 0
        return ret
    End Function 
    
    Public Function GetCostCenterTotal()
        Dim ret as Decimal = costCenterTotal 
        costCenterTotal = 0
        return ret
    End Function 
    
    Public Function GetGrandTotal()
        Dim ret as Decimal = grandTotal
        grandTotal= 0
        return ret
    End Function 
    

提交回复
热议问题