Results 1 to 12 of 12
  1. #1
    DonKaponne is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7

    How to sum the values of duplicate data sets in a table?


    Hello,

    I am facing the problem how to use in Access the in Excel available "sumif" function. There is a table with duplicate data sets for example bank account numbers, where to every bank account are different revenues over the time. My need is to estimate the sum of revenues for every single bank account number. That means, in a first step the duplicate data sets in the table have to be removed. Then it should be build the sum over the revenues for every bank account number.

    Thanks a lot for your advice

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Build a query in access that collects the values you want.
    Export / import that query into Excel.

  3. #3
    DonKaponne is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7
    The problem is I don't know how to build this query. It's not an ordinary query for me. Can you "ranman256" post the SQL code of such a query. If there is another solution within Access, please post it here.

    I have managed to do the first step, to collect the account numbers without the duplicates and to write them into a new table. Now I need to build new query accessing both tables and use the second table as a condition to sum the revenues from the first table.

    Thanks

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    I dont know your table structures.
    It would be like: Select [Name], Sum([AcctValue]) as TotalAmt from table where [person]='Bob Smith')

  5. #5
    DonKaponne is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7
    I have the table "tblTest" with three fields (ID, Field1, Field2). In Field1 are the account numbers, in Field2 are the revenues to them. So how should be build the query so that been selected all account numbers without duplicated (Field1) and in a second step to sum the revenues to every single account number (Field2).

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    ranman's query will work if you filter to a single person. If you want all:

    SELECT [AccountNumber], Sum([AcctValue]) AS TotalAmt FROM table GROUP BY [AccountNumber];

    But do you need duplicates removed before or after the data is summed? Why would there be duplicate data? Do you want to provide sample?
    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.

  7. #7
    DonKaponne is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7
    I need the duplicates removed before summing the data. As an example- you have many account numbers (say 5.000, it's the Field1), that appear many times. There are different revenues to the account numbers (say 15.000, it's the Field2). So the task is to estimate the total revenue to every account number.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Then doesn't sound like duplicate data. What do you mean by 'different' revenues? Each revenue has a code identifier? Have the query summarize by account and revenue code, like:

    SELECT [AccountNumber], [RevenueCode], Sum([AmountField]) AS TotalAmt FROM table GROUP BY [AccountNumber], [RevenueCode];
    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.

  9. #9
    DonKaponne is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7
    It's not so complicated.

    The table (tblTest) looks like:

    Field1 Field2 Field3 Field4 Field5
    101 100$
    102 200$
    103 600$
    101 340,5$
    102 465$
    103 500$
    104 1200$
    101 45$
    ....

    For me are important only Field1 (there is the account number) and Field2 (account turnoover or revenues).

    There is duplicate data in term of the account numbers because one and the same account number occuring many times (in the example account number 101 occurs 3 times). In my table "tblTest" gathering Field1 and Field2 are 15.000 data sets in total, yet there are only 5.000 unique account numbers. I wanna estimate the sum of the account turnover to every account number.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    These are not duplicate records. The account numbers are repeated but the amount values are different.

    Summing the amount values for each account is easily done with an aggregate query. I don't understand the calculation you want to do. What do you mean by 'estimate the sum of the account turnover'? What is the formula to do that?
    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.

  11. #11
    DonKaponne is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    7
    "Summing the amount values for each account is easily done with an aggregate query."
    How is to be build such an aggregate query. Could you post the SQL code please.

    Maybe I haven't express myself in the correct way.

    "The table (tblTest) looks like:

    Field1 Field2 Field3 Field4 Field5
    101 100$
    102 200$
    103 600$
    101 340,5$
    102 465$
    103 500$
    104 1200$
    101 45$
    ...."

    As a result, the query should give out:

    Field1 Field2
    101 (uniques account numbers) 485,5 $ (sume of the amount values (100+ 340,5 +45) for the account number 101 )
    102 ....
    ...
    103
    ...

    Field1 should be without duplicate acount numbers


    I have tried with that SQL code:

    SELECT Distinct ID, Field1, Field2
    FROM tblTest
    WHERE [Field1] HAVING COUNT(*) >= 1
    SUM [Field2] as TotalAmt FROM tblTest
    GROUP BY ID

    but it doesn't work

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    We have already posted several examples of aggregate query. See post number 6.

    Use the query builder.
    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. Table with duplicate values
    By bigchicagobob in forum Queries
    Replies: 1
    Last Post: 02-02-2014, 05:59 PM
  2. Replies: 10
    Last Post: 12-24-2013, 12:53 PM
  3. Crosstab => Multiple Sets of Values
    By Minimalist in forum Queries
    Replies: 1
    Last Post: 01-07-2013, 01:17 PM
  4. Move duplicate values in a different table....
    By jhargram in forum Queries
    Replies: 1
    Last Post: 07-23-2012, 02:06 AM
  5. Duplicate Values in table
    By senthilrg in forum Queries
    Replies: 3
    Last Post: 12-18-2009, 09:24 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