Results 1 to 5 of 5
  1. #1
    NotReese is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    2

    Question Previous Year Data Query Expression

    I need an expression that will pull previous year's assets into the same row as its current year data. All of the data that I have is for the current year (e.g. Payments, Assets, Liabilities, Expenses, etc. for 2010, 2011, and 2012) but I need to pull in 2009 assets into the same database row as the rest of the 2010 data (2010 assets into the 2011 data, 2011 assets into the 2012 data, etc.). Right now I 'm having to copy and paste this information manually into a new column once the query is exported to Excel which is getting cumbersome.



    I figure there has to be a straightforward solution to this but after hours of searching support sites I have come up with absolutely nothing. Is there some sort of lag or "Year-1" expression that would help me solve this issue?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I think what you're asking for is possible, but I've got no clue what your data structure is or what your SQL statments are.

    Is there an chance you can provide a sample database.

    Off the top of my head I can think of a couple of things to do, the first is if your current query is deriving the year from a field on a form or from a [enter the year] type criteria you can create the exact same query for a year prior (just using [Enter the year] -1 as a criteria for example) then linking that 'previous year' query to your current year query and just adding the fields necessary to give you the result you want.

  3. #3
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    It requires that there is a cross referencing ID that is common year to year and unique line to line....such as an Account#. Presuming that exists make a single year query for each year needed...i.e. 2010q 2011q etc.. and then create a new query using those annual queries as the tables. Join them by the Account# and then add the fields you want to see.

  4. #4
    NotReese is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    2

    Re:

    Thanks folks, I'm close to figuring it out I think. I'll post again if I run into any unforeseen issues.

  5. #5
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    The general answer is
    Code:
    SELECT 
       T1.KeyField, 
       T1.YearField, 
       T1.Field1, 
       T1.Field2, 
       T1.Field3, 
       T2.YearField, 
       T2.Field1, 
       T2.Field2, 
       T2.Field3
    FROM
       MyTable As T1
       INNER JOIN 
       MyTable as T2
       ON T1.KeyField = T2.KeyField
       AND T1.Yearfield = T2.YearField + 1;
    Of course, MyTable may need to be an aggregate query that sums up all the individual transactions or something.

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

Similar Threads

  1. Dsum data between to dates for this year and last year
    By sdel_nevo in forum Programming
    Replies: 1
    Last Post: 06-13-2013, 06:48 AM
  2. Query Help - calculate variance previous year
    By brtucker in forum Queries
    Replies: 1
    Last Post: 01-31-2013, 05:40 PM
  3. Query to use previous row's data ?
    By amrut in forum Queries
    Replies: 1
    Last Post: 07-25-2012, 06:20 AM
  4. Replies: 1
    Last Post: 07-20-2012, 03:31 AM
  5. Query can't find Year data
    By G.King in forum Queries
    Replies: 7
    Last Post: 06-23-2011, 03:07 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