Results 1 to 15 of 15
  1. #1
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183

    Creating Fiscal Quarters and Year in queries

    So far, in my query, I have a column for Quarters and under the field of that column I have put a statement:

    Quarter: IIf(Month([VisitDate]) In (4,5,6),"1",IIf(Month([VisitDate]) In (7,8,9),"2",IIf(Month([VisitDate]) In (10,11,12),"3","4")))


    The statement works fine but the problem is it does not tell me which year of does that quarter belongs to. Example: whether it is Quarter 1 of 1999 or Quarter 1 of 2000. Right now it only output either 1 or 2 or 3 or 4.

    Therefore, is there a way where I can command to give me an output like "Quarter 1, 1999", "Quarter 2, 1999", "Quarter, 1, 2000". Basically with respect to the Year that I have in my data?

    I hope someone knows a solution to it.
    Thanks!

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Try Adding another field called 'QuarterYear' in Query Design - like this:

    QuarterYear: [Quarter] & ", " & Year([YourDateField])

    I tried it in a simple query & it worked.

  3. #3
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183
    Quote Originally Posted by Robeen View Post
    Try Adding another field called 'QuarterYear' in Query Design - like this:

    QuarterYear: [Quarter] & ", " & Year([YourDateField])

    I tried it in a simple query & it worked.

    Hi Robeen,

    I tried that and it works well but still when I am running the query it would pull Quarter 4 of the previous year.

    For example:
    Cost Date Quarters Year
    20 12/31/2009 3 2009
    30 3/21/2010 4 2010
    40 2/21/2009 4 2009
    50 6/20/2009 1 2009




    With the above example, if I run a query for 2009 only, Access will every event that happened in 2009. But 2/21/2009 is something that I do not need as it is Q4 for 2008



    I hope you understood what I am trying to explain



    Thanks

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Quarter: IIf(Month([VisitDate]) In (4,5,6),"Q1",IIf(Month([VisitDate]) In (7,8,9),"Q2",IIf(Month([VisitDate]) In (10,11,12),"Q3","Q4"))) & iif(cint(month(visitdate) ) >=7, datepart("yyyy", Visitdate)+1, datepart("yyyy", visitdate))

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    If you want to control which dates show up, you can put a date range under your 'VisitDate' field in the 'Criteria' row in Query Design.

    Try putting something like this in Criteria for VisitDate:
    >#12/31/2009# And <#01/01/2011#

  6. #6
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183
    Quote Originally Posted by rpeare View Post
    Quarter: IIf(Month([VisitDate]) In (4,5,6),"Q1",IIf(Month([VisitDate]) In (7,8,9),"Q2",IIf(Month([VisitDate]) In (10,11,12),"Q3","Q4"))) & iif(cint(month(visitdate) ) >=7, datepart("yyyy", Visitdate)+1, datepart("yyyy", visitdate))

    Thanks rpeare!

    I just tried that and it is giving me error. The error message says the following: "the expression you entered contains invalid syntax. You may have entered an operand without an Operator"

  7. #7
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183
    Quote Originally Posted by Robeen View Post
    If you want to control which dates show up, you can put a date range under your 'VisitDate' field in the 'Criteria' row in Query Design.

    Try putting something like this in Criteria for VisitDate:
    >#12/31/2009# And <#01/01/2011#

    Thanks Robeen! I would do that if I do not have any option left. I am hesitated to put that in to the 'criteria' row as I would have to put that each time I want to do some query.
    I wanted in such a way where I can easily do cross tab query years after years without me going back to the design view and changing the YEAR.

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I have this table

    Code:
    tblTest
    VisitDate
    1/1/2011
    2/1/2011
    3/1/2011
    ...
    11/1/2011
    12/1/2011
    This is the query I'm running

    Code:
    SELECT tblTest.VisitDate, IIf(Month([visitdate])<=3,"Q3",IIf(Month([visitdate])<=6,"Q4",IIf(Month([visitdate])<=9,"Q1","Q2"))) & "-" & IIf(Month([visitdate])>=7,DatePart("yyyy",[visitdate])+1,DatePart("yyyy",[visitdate])) AS Quarter
    FROM tblTest;
    And it's giving me the correct results.

  9. #9
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    nice - I like how you did that rpeare!
    I didn't realize that's what sk88 needed till I saw what you did.

  10. #10
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183
    Quote Originally Posted by rpeare View Post
    I have this table

    Code:
    tblTest
    VisitDate
    1/1/2011
    2/1/2011
    3/1/2011
    ...
    11/1/2011
    12/1/2011
    This is the query I'm running

    Code:
    SELECT tblTest.VisitDate, IIf(Month([visitdate])<=3,"Q3",IIf(Month([visitdate])<=6,"Q4",IIf(Month([visitdate])<=9,"Q1","Q2"))) & "-" & IIf(Month([visitdate])>=7,DatePart("yyyy",[visitdate])+1,DatePart("yyyy",[visitdate])) AS Quarter
    FROM tblTest;
    And it's giving me the correct results.



    I am so sorry to what I am about to ask. I am pretty new to Access so I would need help. My question is -- Where do I insert that SQL code in the query? *embarrassed**

  11. #11
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You don't insert it into your query, you build it like I have (because I don't know the structure of your tables) Create a table with the same name I have with a field of the same name and put in the 1 day for each month of any given year, then save the SQL code I gave you as a query and run it

  12. #12
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    sk88,

    You can create a new query in Design View,
    choose a Table,
    and then click 'View' from the top left,
    and then 'SQL View'

    You will see the skeleton of an SQL statement in the SQL View window.

    That's where you might put the SQL that rpeare posted.

  13. #13
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183
    Quote Originally Posted by rpeare View Post
    You don't insert it into your query, you build it like I have (because I don't know the structure of your tables) Create a table with the same name I have with a field of the same name and put in the 1 day for each month of any given year, then save the SQL code I gave you as a query and run it

    sorry! it works now! Thanks rpeare!!

  14. #14
    sk88 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    183
    Quote Originally Posted by Robeen View Post
    sk88,

    You can create a new query in Design View,
    choose a Table,
    and then click 'View' from the top left,
    and then 'SQL View'

    You will see the skeleton of an SQL statement in the SQL View window.

    That's where you might put the SQL that rpeare posted.

    Thanks again Robeen,
    That was really helpful information!

  15. #15
    Join Date
    Nov 2012
    Posts
    9
    I figured it out. You have been a tremendous help...Thank you so much!!!!

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

Similar Threads

  1. Fiscal Year in Access 2007
    By blindhawkeye in forum Access
    Replies: 1
    Last Post: 08-16-2011, 02:38 PM
  2. Replies: 1
    Last Post: 08-02-2011, 06:46 PM
  3. July-June Fiscal Year, Not Jan-Dec
    By blazerboy6 in forum Access
    Replies: 2
    Last Post: 04-14-2011, 02:23 PM
  4. fiscal year
    By RedGoneWILD in forum Programming
    Replies: 4
    Last Post: 08-04-2010, 01:38 PM
  5. Replies: 2
    Last Post: 06-30-2010, 12:26 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