Results 1 to 2 of 2
  1. #1
    brtucker is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    1

    Query Help - calculate variance previous year

    Any help on this query would be appreciates. The data looks like this

    ID P1 P2 P3 YEAR
    100100 500 100 100 2012
    100100 300 200 300 2011
    999999 300 200 300 2012
    999999 500 100 100 2011



    I would like to calculate the variance between the periods for each ID. ie. P2 in 2012 - P2 in 2011, etc. The final table should look like this...

    ID P1 P2 P3
    100100 200 -100 -200
    999999 -200 100 200

    thanks,
    Brent

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Your data is not normalized structure.

    Concerned with only 2011 and 2012?

    Consider:

    Query1
    SELECT Table1.ID, Sum(IIf([Year]=2012,[P1],Null)) AS 2012P1, Sum(IIf([Year]=2012,[P2],Null)) AS 2012P2, Sum(IIf([Year]=2012,[P3],Null)) AS 2012P3, Sum(IIf([Year]=2011,[P1],Null)) AS 2011P1, Sum(IIf([Year]=2011,[P2],Null)) AS 2011P2, Sum(IIf([Year]=2012,[P3],Null)) AS 2011P3
    FROM Table1
    GROUP BY Table1.ID;

    Query2
    use the above query as data source and create fields with expressions that calculate difference of respective fields

    Have to rebuild queries each year.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 01-25-2013, 05:20 AM
  2. Replies: 4
    Last Post: 07-30-2012, 11:55 AM
  3. Replies: 3
    Last Post: 06-19-2012, 10:42 PM
  4. Calculate Percentage based on previous column
    By VictoriaAlbert in forum Queries
    Replies: 1
    Last Post: 08-13-2011, 01:30 PM
  5. Replies: 11
    Last Post: 08-04-2010, 04: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