SSRS code variable resetting on new page

前端 未结 3 1818
南方客
南方客 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:26

    Finally found the solution myself. Here it is, add Shared to the variable declarations:

    Public Shared Dim GroupMedTotal as Integer
    Public Shared Dim GrandMedTotal as Integer
    
    0 讨论(0)
  • 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 
    
    0 讨论(0)
  • 2021-01-05 03:34

    I don't know where do you use this. but in your case, if I were you, I just use simple expression to check visibility of SUM

    for example I'd use Right Click On Sum Box \ Select Expression \ then use IIF(SUM <> 0, sum. "")

    It worked on every where and wont reset, in your case you have a Region and your code will reset in every region so you willface with serios isses if you don't change your way.

    0 讨论(0)
提交回复
热议问题