Subtotal of grouped values (Matrix)

  • Hi,

    I have a Matrix which has data as below:

    col1 col2 col3 Total

    A 1 2 3

    A 4 1 5

    B 1 1 2

    B 2 2 4

    I want the subtotal for 2 sections A and B as follows:

    col1 col2 col3 Total

    A 1 2 3

    A 4 3 7

    Total 5 5 10

    B 1 1 2

    B 3 2 5

    Total 4 3 7

    Thanks in advance!

  • Hi,

    For the sub total, the rollup method is best to achieve,

    Or use this simple statement

    select * from MYTABLE

    union all

    select col1+' TOTAL',sum(col2),sum(col3),sum(Total) from MYTABLE

    group by col1

    order by col1

  • Very easiliy

    Add a row group, grouped by 'colA'.

    Then add a total row.

    Use the drop down to select the data value as you normally would.

    Job done

    If thats not clear see this page

    http://technet.microsoft.com/en-us/library/bb630415.aspx



    Clear Sky SQL
    My Blog[/url]

  • Arun: Thanks for the help.

    Dave : Thanks, I did not state the problem clear enough. My bad.

    I have to group by col1 and YYYYDD.

    So basically, I need two groupings but I am not sure how to set them.

    col1 YYYYDD col2 col3 Total

    A 200901 1 2 3

    A 200902 4 3 7

    Total 5 5 10

    col1 YYYYDD col2 col3 Total

    B 200901 2 2 4

    B 200902 4 9 13

    Total 6 11 17

    Thanks in advance!

  • If following is the results of you dataset, you don't need a matrix report

    col1 YYYYDD col2 col3 Total

    A 200901 1 2 3

    A 200902 4 1 5

    B 200902 1 1 2

    B 200902 2 2 4

    You only need a tabular report. Add a parent group by col1 with a group footer, in the group footer row, add sum expression.

    (you sample data only looks like group by col1, not group by col1 and YYYYDD)

  • Thanks for the reply.

    You are right, its a typo 🙂

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply