Results 1 to 6 of 6
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862

    Group on Month in query

    Hi all,
    I am trying to minimize the amount of queries and fountcrosstab queries quite helpful. What do I need to do to group dates on currentmonth and back for 6 months total? I would like the months to start on the15th. Remember this is for a crosstab query.
    Thanks


    T



  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    before you cross tab, create a query and add a new calc field: Month: Month([date]) (or however you want to group it) , to give you a 'caption' for the month you want to xtab.
    THEN crosstab the above query and you have your caption.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    There isn't a way to do it in the crosstab itself?

    TRANSFORM Count(Inquires.Inq_ID) AS CountOfInq_ID
    SELECT Inquires.Section_ID
    FROM Inquires
    GROUP BY Inquires.Section_ID
    PIVOT Format([Date Sent],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"," Sep","Oct","Nov","Dec");

    I was hoping you could change it in the PIVOT line Between DateSerial(Year(Date()),Month(Date())+1,-15) or something like that.

    Thanks

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    If you want your months to be 15th thru 14th, this complicates because the period crosses months and years. Never seen this.

    How should Access know "the record dated April 1 really belongs with month Mar".

    Yes, an expression to calculate the 'month' each record falls in maybe could be built into the CROSSTAB and that calculated field serve as the PIVOT field (just as is now being done with the Format() expression), but I expect it won't be a simple expression. I am still pondering.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Thanks June7,

    For simplicities sake, lets stay in calendar months instead of on the 15th.
    Month 1: Between DateSerial(Year(Date()),Month(Date())-1,0) And now()
    Month 2: Between DateSerial(Year(Date()),Month(Date())-2,0) And DateSerial(Year(Date()),Month(Date())-1,0)
    Month 3: Between DateSerial(Year(Date()),Month(Date())-3,0) And DateSerial(Year(Date()),Month(Date())-2,0)
    Month 4: Between DateSerial(Year(Date()),Month(Date())-4,0) And DateSerial(Year(Date()),Month(Date())-3,0)
    Month 5: Between DateSerial(Year(Date()),Month(Date())-5,0) And DateSerial(Year(Date()),Month(Date())-4,0)
    Month 6: Between DateSerial(Year(Date()),Month(Date())-6,0) And DateSerial(Year(Date()),Month(Date())-5,0)

    That's what I have been using in separate Queries. Since I can cut out 6 queries with crosstab queries, how would I incorporate these into one?

    What about some type of 30 day interval?

    Malcom,
    Since I am a novice at this, I don't understand what you mean? I can already format the month off of this for each month on the report:
    =Format(DateAdd("m",-5,Date()),"dd mmm yyyy")

    Thanks

  6. #6
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    I changed the SQL a little and got it down to only the months where the month has data and the data is consolidated into the month it is in as a total for that month..

    TRANSFORM Count(Inquires.Inq_ID) AS CountOfInq_ID
    SELECT Inquires.Inq_Type
    FROM Inquires
    WHERE (((Inquires.[Date Sent]) Between DateSerial(Year(Date()),Month(Date())-6,0) And Now()))
    GROUP BY Inquires.Inq_Type
    PIVOT Format([Date Sent],"mmm yyyy");

    That's a step forward, It takes the last 6 months, but where there is no data the month isn't shown. But that's another issue.

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

Similar Threads

  1. Group by month - can't get it to work !
    By SpookiePower in forum Queries
    Replies: 4
    Last Post: 12-15-2013, 04:47 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