Results 1 to 4 of 4
  1. #1
    jmuirman1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2016
    Posts
    84

    Want to show data in separate columns for 3 previous years


    how can i show 3 or 4 columns of annual data for same category/field in same report?

    main field is "Set-up Date"

    so, Set-up Date 2017; Set-up Date 2018 and Set-up Date 2019?

    Thanks,

    John

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Look into a Cross tab query, and format your date field something like

    Format([Yourdate],"yyyy")

    in the grouping.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    Apr 2017
    Posts
    1,679
    Maybe like this:
    Code:
    SELECT k.Key1, k.Key2, t17.Cnt17, t17.Sum17, t18.Cnt18, t18.Sum18, t19.Cnt19, t19.Sum19
    FROM 
    (((SELECT DISTINCT Key1, Key2 FROM YourTable WHERE Year(SetUpDate) BETWEEN 2017 AND 2019) AS k
    LEFT JOIN (SELECT Key1, Key2, Count(Key1) AS Cnt17, SUM(SomeField) AS Sum17) FROM YourTable WHERE Year(SetupDate)=2017 GROUP BY Key1, Key2) AS t17 ON t17.Key1 = k.Key1 AND t17.Key2 = k.Key2)
    LEFT JOIN (SELECT Key1, Key2, Count(Key1) AS Cnt18, SUM(SomeField) AS Sum18) FROM YourTable WHERE Year(SetupDate)=2018 GROUP BY Key1, Key2) AS t18 ON t18.Key1 = k.Key1 AND t18.Key2 = k.Key2)
    LEFT JOIN (SELECT Key1, Key2, Count(Key1) AS Cnt19, SUM(SomeField) AS Sum19) FROM YourTable WHERE Year(SetupDate)=2019 GROUP BY Key1, Key2) AS t19 ON t19.Key1 = k.Key1 AND t19.Key2 = k.Key2

  4. #4
    jmuirman1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2016
    Posts
    84
    Thanks - I think I'm heading in the right direction now.

    Having trouble though with having 2017,2018 and 2019 columns - do i need 3 queries?

    if I use -- Between #1/1/2018# And #1/1/2019# in one column and Between #1/1/2017# And #1/1/2018# in the second column of course no results show up. Do i need some type of "or" function?

    Thanks,

    John

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

Similar Threads

  1. Replies: 2
    Last Post: 06-02-2017, 09:30 AM
  2. Replies: 2
    Last Post: 05-23-2016, 05:31 AM
  3. Querying this DD/MM in all previous years
    By jmwebster91 in forum Access
    Replies: 9
    Last Post: 05-23-2016, 04:52 AM
  4. only show this years results
    By sdel_nevo in forum Queries
    Replies: 4
    Last Post: 12-16-2014, 06:39 AM
  5. Replies: 5
    Last Post: 03-29-2012, 09:21 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