Results 1 to 5 of 5
  1. #1
    jos1972 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    2

    extract last 8 weeks from data field with yearweek

    hello,


    I'm new to the forum and pretty new to access, so I hope someone can help me with this question.

    I have a column in my database with the year and week in the following format:20141 for week 1 in 2014 and 201452 for week 52.
    Now I would like to build an if then functions that returns the value of another column only if the week falls in the region "last 8 weeks".
    As an example: for week 1 2015 the iff then function should return week 46-2014 - week 1 2015.
    So far the below if then worked, however now that we are in the first week of the new year in only returns week 1 2015.

    CW_LST8WK_QTY: IIf([tblData]![Week]>=([Forms]![frmImport]![txtWeek]-7) And [tblData]![Week]<=[Forms]![frmImport]![txtWeek],[tblData]![LAST_WEEK],Null)

    Thank you for your help.
    With best regards,
    Jos

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Jos,


    Just a comment related to design. Relational databases are easiest to use and maintain when you design with atomic data. That is, 1 fact, 1 field.
    Difficulties almost always arise when trying to codify various facts into a single field.

    don database principles

  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    I have a column in my database with the year and week in the following format:20141 for week 1 in 2014 and 201452 for week 52.
    What field type have you used to store data number/text ?

    To get what you want, you need to separate the week number from the year and then compare. One more way is to convert your field to a date and use DateAdd function to retrieve the data for last 8 weeks. See here http://www.techonthenet.com/access/f...te/dateadd.php .

  4. #4
    jos1972 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    2
    Quote Originally Posted by orange View Post
    Jos,


    Just a comment related to design. Relational databases are easiest to use and maintain when you design with atomic data. That is, 1 fact, 1 field.
    Difficulties almost always arise when trying to codify various facts into a single field.

    don database principles
    hello orange,
    thank you for your reply. Actually the dataset has a separate column for weeks and years. Does that make it easier?
    thnx

  5. #5
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    This might work for you.

    Using

    SELECT TOP 8 *
    FROM TABLENAME
    ORDER BY YEAR DESC, WEEKNO DESC;

    For more deatil,
    http://www.blueclaw-db.com/accessque...select_top.htm

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

Similar Threads

  1. Combine Multiple Weeks of Data
    By Rustin788 in forum Queries
    Replies: 1
    Last Post: 09-24-2014, 08:40 AM
  2. Querying specific weeks data within any given year?
    By McArthurGDM in forum Queries
    Replies: 1
    Last Post: 07-30-2014, 02:02 PM
  3. Replies: 3
    Last Post: 11-22-2011, 11:06 AM
  4. Replies: 13
    Last Post: 10-26-2011, 03:49 AM
  5. Comparing consecutive weeks data
    By foamcows in forum Queries
    Replies: 1
    Last Post: 08-16-2011, 08:20 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