Forum Discussion

Tony2021's avatar
Tony2021
Steel Contributor
Feb 17, 2022

Sum by Year in addition to by Month

Hello,    I have developed the following query that sums by month.  I want to add a sum by year too.  How to best do this?  thank you in advance...   SELECT Format([WithdrawalDate],'mmmm yyyy'...
  • George_Hepworth's avatar
    George_Hepworth
    Feb 17, 2022

    George_Hepworth 

    Maybe it needs to be:

     

    SELECT "Monthly" AS [Date Period], Format([WithdrawalDate],'mmmm yyyy') AS [TimePeriod], Sum(tblDraws_CAWC.LocalAcctNoLR) AS SumOfLocalAcctNoLR, Sum(tblDraws_CAWC.LiquidityRes) AS SumOfLiquidityRes, Sum(tblDraws_CAWC.TLocalAcctCalc) AS SumOfTLocalAcctCalc
    FROM tblDraws_CAWC
    GROUP BY Format([WithdrawalDate],'mmmm yyyy')

     

    UNION 

    SELECT "Yearly" AS [Date Period], Format([WithdrawalDate],'yyyy') AS [TimePeriod], Sum(tblDraws_CAWC.LocalAcctNoLR) AS SumOfLocalAcctNoLR, Sum(tblDraws_CAWC.LiquidityRes) AS SumOfLiquidityRes, Sum(tblDraws_CAWC.TLocalAcctCalc) AS SumOfTLocalAcctCalc
    FROM tblDraws_CAWC
    GROUP BY Format([WithdrawalDate],'yyyy');

     

    You'll also want to add an Order by clause to sort the records as needed.

Resources