Search code examples
reporting-servicesssrs-2012reportbuilder3.0

Compare 2 dynamically created matrix columns to get a difference


I have a matrix set up with a Row Group called "company", a Column Group called "Year" and a value field that is a sum of charges through the year called revenue. The column Group will end up having 2 columns in it that are provided through user input. The end results is a matrix that will look something like this:

         Year 1 | Year 2
Company:    $500    $250
Company2:   $750    $250

What I would like to do is add a column to the matrix that calculates the change from year 1 to year 2. Is there a way to do this within the matrix such as adding a new column with an expression that compares the 2 entries in the row or will I need to manipulate the SQL code to create a column that does this within the code? To that end here is a view of the code for the dataset if that is the way I need to go:

SELECT
 company.cmp_id
,company.Company
,ChargeDetails.[Bill To ID]
,ChargeDetails.[Delivery Year]
,ChargeDetails.Revenue
FROM
ChargeDetails
LEFT OUTER JOIN company
ON ChargeDetails.[Bill To ID] = company.cmp_id
WHERE
ChargeDetails.[Delivery Year] = @DeliveryYear 
OR 
ChargeDetails.[Delivery Year] = @ComparisonYear2
ORDER BY ChargeDetails.[Delivery Year] DESC,ChargeDetails.Revenue DESC;`

Solution

  • I ended up using the following as the expression in the change column.

    =sum(iif(Fields!Delivery_Year.Value=Parameters!DeliveryYear.Value,1,0)*Fields!Revenue.Value) -  sum(iif(Fields!Delivery_Year.Value=Parameters!ComparisonYear2.Value,1,0)* Fields!Revenue.Value)