Results 1 to 3 of 3
  1. #1
    ohthesilhouettes is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    7

    Creating Compound summations etc.

    Hi again!



    I have a series of records each with a count of treaties. I want to either add or subtract the number of counts to the previous record grouped by the count of treaties, the country that is involved, and whether they joined or left the treaty.

    TreatyCount; Country; YearDate; Action
    10; USA; 1975; joined
    1; USA; 1980; left
    3; USA; 1980; joined
    1; USA; 1990; joined
    5; France; 1980; joined
    2; France; 1981; joined
    3;France; 1982; joined
    1;France 1985; left

    I need to make a table that shows at any given year, adds the number of treaties a country joins from the previous year and subtracts the number of treaties if a country leaves.

    -Note the countries begin at different time points (USA started joining treaties in 1975 while France started joining treaties in 1980)
    -Also note that in one year a country can join treaties and leave treaties all in one year (in 1980 USA left 1treaty and joined 3 others)
    -Lastly, there are years (not listed) in which the country neither joined nor left a treaty. I will assume that during these in-between years, their treaty numbers haven't changed(ie USA did not join or leave any treaties between 1976-1979 and therefore the treaty count is the same as it was in 1975)

    The resulting table should look like this

    TreatyTotals; Country; YearDate; Action
    10; USA; 1975; joined
    9; USA; 1980; left
    11; USA; 1980; joined
    12; USA; 1990; joined
    5; France; 1980; joined
    7; France; 1981; joined
    10;France; 1982; joined
    9;France 1985; left

    I know this is probably a complicated query and may need a lot of intervening steps. Does the layout of my table even allow these calculations to work?

    I have been looking into IFF functions but have not been able to sum within the group of records I am interested in.

    My guess is that the iff function would say, "If Action = "joined", Add TreatyCount from the previous record Grouped by same Country, If not then subtract TreatyCount from the previous record Grouped by same Country"

    I got this far: TreatyTotals: Iff(Action = "joined", Sum(TreatyCount)........)

    I also tried using the domain aggregate functions (Dsum) but ran into the same problem.

    If anyone can give me some pointers on how to do this I would very much appreciate it. Thanks a bunch!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi

    Is this a table or the results of a query.
    TreatyCount; Country; YearDate; Action
    10; USA; 1975; joined
    1; USA; 1980; left
    3; USA; 1980; joined
    1; USA; 1990; joined
    5; France; 1980; joined
    2; France; 1981; joined
    3;France; 1982; joined
    1;France 1985; left
    The reason I ask is because the numbers in the first column look as though they should be coming from a query not a table. Calculations should NOT normally be stored in table fields.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ohthesilhouettes is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    7
    The first table did come from a query previously but I made the query output a table for me using SELECT INTO. Now it is a table and I want to make a query FROM this table to create the second table.
    Hope this makes sense. Thanks

    -Michelle

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

Similar Threads

  1. Creating a '+1'-button
    By Propaganistas in forum Forms
    Replies: 3
    Last Post: 10-30-2010, 03:52 AM
  2. Creating Set up Files
    By Alex Motilal in forum Access
    Replies: 2
    Last Post: 04-12-2010, 11:10 PM
  3. Help with creating a Report..
    By TylerZ07 in forum Reports
    Replies: 2
    Last Post: 12-11-2009, 07:51 AM
  4. Help with creating a database
    By ITChevyUSSNY in forum Access
    Replies: 0
    Last Post: 07-31-2009, 05:48 AM
  5. Creating database
    By ramzyamal in forum Database Design
    Replies: 1
    Last Post: 05-07-2007, 08:53 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