ROLLUP to calculate Month total for all Categories

  • Good Afternoon,

    I have built a table with four columns:  Period(Month), Category, Numerator, Denominator. Period(Month) is an Alias name, and Numerator and Denominator are calculated columns:

    SELECT

    ,convert(NVARCHAR,Date,3) as 'Period(Month)'

    ,[Category]

    , sum([X]) as 'Numerator'

    ,SUM([Y]) as 'Denominator'

    FROM Tabl1

    GROUP BY [Category], convert(NVARCHAR,Date,3),CAST(Date AS date)

    ORDER BY convert(NVARCHAR,Date,3) desc

    Now I want an additional record added at the end of all records for each 'Period(Month)' containing the total Numerators and Denominators for that month (but must NOT be broken down by Category totals within each month).

    I assume that I need ROLLUP function for this purpose, but I was having problems ROLLUP in achieving the desired end result because 1) The Totals were being tallied for each Category for each month and 2) The 'Aliased' columns.

    Kindly advise.

     

     

     

     

    • This topic was modified 59 minutes ago by Reh23.
    • This topic was modified 56 minutes ago by Reh23.
    • This topic was modified 53 minutes ago by Reh23.
    • This topic was modified 52 minutes ago by Reh23.

Viewing post 1 (of 1 total)

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