Search code examples
sqlsql-serverreporting-servicesssrs-2012ssrs-tablix

% of Column Total SSRS Matrix


I'm trying to display an SSRS row subgroup value as a percentage of its column total grouped by the row subgroup.

My goal:

1

Notice how the values in red display as a percentage of the value in the RowSubGroupTotal, whereas the RowSubGroupTotal displays as percentage of the ColumnGroup total.

What I currently have:

enter image description here

The red values display as a percentage of the ColumnGroup total (just like the RowSubGroupTotals do).

How do I change those red values to rollup to 100% - their values as a percentage of the RowSubGroupTotal?

My matrix:

enter image description here

Raw data: RawData

I want the red values to be a percentage of the RowSubGroupTotal (3/4 = 75%, 1/4 = 25%). I want the RowSubGroupTotal to be a percentage of the column subtotal (4/25 = 16%, 9/25 = 36%).


Solution

  • Assuming the field is called Amount, your outer row group is called BlueRowGroup and your dataset is called 'DataSet1` then the expression for the red rows would be something like

    =SUM(Fields!Amount.Value) / SUM(Fields!Amount.Value, "BlueRowGroup")
    

    and the blue rows would be

    =SUM(Fields!Amount.Value) / SUM(Fields!Amount.Value, "DataSet1")
    

    The first part of the expression does not state the scope as this will be the scope of the textbox the expression resides in. The second part states the scope of the total amount we want to divide by, so for the red rows, we want to divide the amount by the total amount from the next group up (BlueRowGoup). For the blue rows we want the amount to be divided by the total for the entire dataset so we use the dataset name as the scope.

    Here is a working exmaple....

    I created some data to mirror your sample data, just changed the names to avoid confusing fields with groups/scopes.

    DECLARE @t TABLE(RowGroup varchar(10), SubGroup varchar(10), Amount int)
    INSERT INTO @t VALUES 
    ('Alpha', 'Red', 2),
    ('Alpha', 'Red', 1),
    ('Alpha', 'Green', 0),
    ('Alpha', 'Blue', 1),
    ('Bravo', 'Red', 1),
    ('Bravo', 'Green', 0),
    ('Bravo', 'Blue', 4),
    ('Bravo', 'Blue', 4),
    ('Charlie', 'Red', 0),
    ('Charlie', 'Green', 4),
    ('Charlie', 'Blue', 2),
    ('Charlie', 'Blue', 6)
    
    SELECT * FROM @t
    

    I added a simple tablix showing both the actual underlying numbers and the %'s, which looks like this.

    enter image description here

    I set the expression as earlier in this answer.

    This gives the following result...

    enter image description here