Results 1 to 5 of 5
  1. #1
    SpookiePower is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Denmark
    Posts
    14

    Group by month - can't get it to work !

    I have a table with 3 columns, A and B and DateSales



    I want to SUM A and B and group the result in months like this -

    Month A B
    Jan 100 300
    Feb 50 90
    ... ... ...

    My SQL looks like this -

    Select DateSales AS Month, SUM(A) AS A, SUM(B) AS B
    FROM Table
    GROUP by DateSales.Month

    I have tried many different settings with the GROUP BY, but I get an error each time in that line.

    Someone who can help ?

    - Kim -

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Untested, but you could try:
    Code:
    Select Month(DateSales) AS Mth, SUM(A) AS A, SUM(B) AS B
    FROM Table
    GROUP by Mth
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    SpookiePower is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Denmark
    Posts
    14
    I think it's pretty close, but still not working.

    I get this error - "You tried to execute a query that does not include the specified expression 'Month(DateSales)' as part of an aggregate function".

    Could it be something with my date formatting ? My DateSales column has the date format 24-12-2013.

    - Kim -

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Have tested below. Works for me.
    Code:
    SELECT Month([DateSales]) AS Mth, Sum(A) AS AA, Sum(B) AS BB
    FROM Table
    GROUP BY Month([DateSales]);
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    SpookiePower is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Denmark
    Posts
    14
    It works - Thanks

    - Kim -

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Group Report by Day not month?
    By bradleyg in forum Reports
    Replies: 2
    Last Post: 09-17-2013, 06:50 PM
  2. Replies: 12
    Last Post: 12-05-2012, 10:44 PM
  3. Replies: 6
    Last Post: 11-19-2012, 09:30 AM
  4. Query group by month and sum
    By Adele in forum Queries
    Replies: 4
    Last Post: 07-13-2011, 09:09 AM
  5. How to group by month
    By okrobie in forum Queries
    Replies: 4
    Last Post: 06-09-2011, 04:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums