how to subtract adjacent columns in an ssrs matrix

前端 未结 2 621
深忆病人
深忆病人 2021-01-24 23:44

\"MyI have an ssrs matrix which looks like the one below :

               Month(Columns)
            


        
相关标签:
2条回答
  • 2021-01-25 00:26

    If you are grouping your columns by month then you don't need to use the SumIif

    You can use a expression such as =Sum(Fields!Products.Value) to get the sum of all products in that particular month. If you want to see the difference between the current month and the previous month then if you enter the below expression in a cell within the month column group...

    =Iif(Previous(Fields!MONTH.Value) = Nothing, 0, 
    Sum(Fields!Products.Value) - Previous(Sum(Fields!Products.Value)))
    

    You need the null check in this instance as the first month will return nothing for previous.

    If you have overlapping row and column row groups (which I believe you do) then you won't be able to use Previous as it isn't supported :-(


    I think that the only solution is to use some custom code.

    There is a link here

    Public Shared previous as Integer
    Public Shared current as Integer
      Public Shared Function GetCurrent(Item as Integer) as Integer
         previous=current
         current=Item
         return current
      End Function
    
      Public Shared Function GetPrevious()
         return previous
      End Function
    

    Then your usage would be something like

    =Code.GetCurrent(Sum(Fields!Products.Value)) - Code.GetPrevious()
    
    0 讨论(0)
  • 2021-01-25 00:32

    I found a way to calculate the differences between Matrix columns using the 'previous' function by adding the column grouping name.

    =Previous(Sum(Fields!AMOUNT.Value),"PeriodGroupName")
    

    Look here for a little more detail. http://www.tricks-and-tips.nl/tips-and-tricks/sql/ssrs/ssrs-matrix-compare-column-values And here for the documentation. https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms156372(v=sql.105)

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