Results 1 to 14 of 14
  1. #1
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283

    returning current quarter from yyyymm short text field

    Hello gurus,



    I have a short text field that contains year and month in the following format yyyymm (ex 201701) I am trying to use that field to return data for the current quarter. Basically if the actual date is April 12, 2017 I would like all data from Q2 (Apr-Jun) returned.

    I have been playing with date part q and can't seem to get it to work.
    Any ideas?

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Datepart("q",datefield) should work. What have you currently got


    Sent from my iPhone using Tapatalk

  3. #3
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    I see weird results though. I added the month column as well to check the quarter field and this is what I see

    Quarter (derived from above) Month
    2 11
    2 8
    1 6
    1 4
    2 12

    I would see month 12 as being Q4, month 8 as being Q3 etc.

  4. #4
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Is datefield actually a date field? Or a text field storing 201701?

    Does month (datefield) return the correct month?


    Sent from my iPhone using Tapatalk

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    to determine the quarter from your datenum of yyyymm use

    (val(right(datenum,2))\4)+1

    note the \

    for a comparison in a criteria for example

    WHERE (val(right(datenum,2))\4)+1=datepart("q",date())

  6. #6
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    It is a short text field

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Then Ajax method is perfect. Datepart only works on a date field.


    Sent from my iPhone using Tapatalk

  8. #8
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    (Val(Right([YEAR_MONTH_NUM],2))\4)+1

    returns data like this
    Quarter Month
    3 11 this should be Q4
    3 8 this is correct
    2 7 this should be Q3

    some look right and others are off

  9. #9
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Try using int in front of first bracket


    Sent from my iPhone using Tapatalk

  10. #10
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    Int(Val(Right([YEAR_MONTH_NUM],2))\4)+1

    Tried this

    same results as above. Some right some not

  11. #11
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Ok try fix instead of int


    Sent from my iPhone using Tapatalk

  12. #12
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    everyone is correct except the following

    Q M
    2 7 should be Q3
    3 10 should be Q4
    3 11 should be Q4

    it is very strange

  13. #13
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Use fix but 3 instead of 4


    Sent from my iPhone using Tapatalk

  14. #14
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    I did this and it works

    update query to change the text field yyyymm to a date field using the same 2 numbers for day as month since I really only care about month and year

    then used this as criteria

    Year([YEAR_MONTH_NUM])=Year(Now()) And DatePart("q",[YEAR_MONTH_NUM])=DatePart("q",Now())

    Thanks for all your help on this....led me down the right path as always

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

Similar Threads

  1. Replies: 2
    Last Post: 04-13-2017, 03:00 PM
  2. Replies: 1
    Last Post: 05-18-2016, 09:46 AM
  3. Replies: 2
    Last Post: 02-10-2015, 02:12 PM
  4. Replies: 25
    Last Post: 11-16-2012, 12:47 PM
  5. Display previous quarter data when quarter is selected
    By rlsublime in forum Programming
    Replies: 1
    Last Post: 07-03-2012, 03:12 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