Results 1 to 4 of 4
  1. #1
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410

    Previous Quarter Reporting Based on CalenderMonth

    Hello,
    I am trying to sum WagesSubjToWitholding for the previous quarter.
    So, run the previous quarter every quarter of the calendar year.

    Here's a snippet
    Code:
     Sum(IIf([CalendarMonth] In ("01","02","03"),[WagesSubjToWithholding],0)) AS Q1, Sum(IIf([CalendarMonth] In ("04","05","06"),[WagesSubjToWithholding],0)) AS Q2, Sum(IIf([CalendarMonth] In ("07","08","09"),[WagesSubjToWithholding],0)) AS Q3, Sum(IIf([CalendarMonth] In ("10","11","12"),[WagesSubjToWithholding],0)) AS Q4, (Val([CalendarMonth])+2)\3 AS Quarter
    
    WHERE (((PR_EmployeeTaxHistory.CalendarYear)=Year(Date())))
    I am not sure how to use
    Code:
    (Val([CalendarMonth])+2)\3
    due to the only fields in the table are CalendarYear and CalendarMonth, no actual Date field.

    What is the syntax to Sum the previous quarter only and not separately with Q1, Q2, Q3, Q4?

    And the 4th quarter needs to report at the beginning of next year.
    So the 4th quarters; CalendarMonth IN ("10","11",12") would show AS PrevQtr in the first quarter in 2020



    Hopefully I made sense?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    I have a form with txtStart,and txtEnd.
    user can free form pick the dates or select combo boxes,like Quarters, month.
    This will fill in the 2 boxes.

    Q1 uses these :
    select * from table where [dateFld] between forms!myForm!txtstart and forms!myForm!txtEnd.

    there are another 2 text boxes....txtStartPrev and txtEndPrev.
    Q2 pulls the previous dates of the ones in Q1. Be it day,month,quarter.

  3. #3
    aellistechsupport is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    410
    Thank you however this needs to be without user input

    Found this
    Code:
    Sum(Abs( Format(DateAdd("q",-1,Date()),"yyyyq") = Format(DateSerial([CalendarYear],[CalendarMonth],1),"yyyyq")) * [WagesSubjToWithholding]) AS PrevQtr


    Seems to be working. Not sure how to test the 4th quarter in the next year though but looks like it should work.

  4. #4
    Join Date
    Apr 2017
    Posts
    1,679
    The formula to calculate previous quarter in format yyyyq:
    Code:
    PreviousQuarter = =100*([CalendarYear]+(INT(([CalendarMonth]-1)/3)=0))+INT((CalendarMonth]-1)/3)-(INT(([CalendarMonth]-1)/3)=0)*4
    From there on it is easy!
    When calculating form control value, you use DSum() with formula for previous quarter as parameter;
    When creating an aggregate query, you calculate PreviousQuarter field using the formula, and group by same formula.

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

Similar Threads

  1. Replies: 1
    Last Post: 04-18-2019, 08:52 AM
  2. Replies: 12
    Last Post: 11-15-2017, 06:58 PM
  3. Limit LOCKUP based on previous enter value
    By viking123 in forum Access
    Replies: 3
    Last Post: 08-10-2016, 10:00 AM
  4. Display previous quarter data when quarter is selected
    By rlsublime in forum Programming
    Replies: 1
    Last Post: 07-03-2012, 03:12 PM
  5. New record based on previous
    By Zingrrl in forum Forms
    Replies: 1
    Last Post: 11-19-2011, 01:16 PM

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