Results 1 to 2 of 2
  1. #1
    Volodos86 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3

    Sum with conditions_PROBLEM large dataset NEWSPAPER

    Dear all,

    I have to solve a problem if possible.
    I have a lot of rows. The first column identifies the year of publication of a newspaper wilhe the other columns the number of access per year.

    Year of publication Newspaper 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995
    1985 Times 1 9 4 1 2 1 5 1 6 6 8
    1985 Le Monde 2 0 3 4 1 1 1 4 2 2 2
    1986 La Repubblica 0 1 3 6 1 1 4 4 6 5 2


    1986 ...
    1987 ...
    1987 ...

    I need to try a SQL code which allows me to sum the number of access in the following 5 years after the publication year.
    For instance. For the first row, the program should sum from 1985 to 1989
    While in the third row from 1986 to 1990

    The problem is that I have 500000 rows with a lot of publications years, so I need to automatize the process

    Thank you so much

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    This would be fairly easy if data was normalized. In other words, if the table structure was like:

    Newspaper YearPub YearAccess QtyAccess
    Times 1985 1985 1
    Times 1985 1986 9
    Times 1985 1987 4
    Times 1985 1988 1
    Times 1985 1989 2
    Times 1985 1990 1
    Le Monde 1985 1985 2
    Le Monde 1985 1986
    Le Monde 1985 1987 3


    Then query like:
    SELECT Newspaper, YearPub, Sum(IIf([YearAccess] BETWEEN [YearPub] AND [YearPub] + 4, [QtyAccess],0)) AS TotQty FROM tablename GROUP BY Newspaper, YearPub;

    Otherwise, I think you will need a VBA procedure to deal with present data structure.
    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. Multiple Reports from refreshing dataset
    By dczeman in forum Reports
    Replies: 3
    Last Post: 03-06-2013, 04:04 PM
  2. How to run macro on filtered dataset
    By FredLanger in forum Forms
    Replies: 7
    Last Post: 04-02-2012, 12:27 PM
  3. Dataset returning different results
    By Juan23 in forum Programming
    Replies: 8
    Last Post: 09-16-2011, 03:03 PM
  4. Help filtering a dirty dataset
    By za20001 in forum Queries
    Replies: 0
    Last Post: 04-16-2011, 10:51 AM
  5. Replies: 1
    Last Post: 03-09-2010, 10:23 AM

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