Results 1 to 5 of 5
  1. #1
    wojosh6 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    8

    Adding Subtotals to a Table or Query

    Hi Folks,



    First time posting here. I have a massive (850K records) table that is setup somewhat similar to the table below. What I am attempting to do in the "%Split" column is find that specific line item's percentage makeup of the total counterparty. For example, within the Jackson counterparty we have three CUSIPs that total 200. I know that abc123 makes up 12.5% of the counterparty total, but I can't quite figure out the code or design view setup to perform this calculation. I get stuck trying to find a subtotal for each counterparty grouping.

    Any help is greatly appreciated!
    Counterparty CUSIP Amount %Split
    Jackson abc123 25
    Jackson abc789 50
    Jackson abc456 125
    Johnson abc123 50
    Johnson abc999 50
    Johnson abcefg 100
    Mellon qqq123 200
    Mellon abc123 150

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The approach I would use would be to make a separate summation query to get the totals for each counterparty, then link that query to the one above on the counterparty ID. You would then use the sum values from that second query to calculate the percentages.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Consider building a report using its Sorting & Grouping features with aggregate calcs in group and report footers.
    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.

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    or this query will work, but with 850k records, ensure you have indexed counterparty

    Code:
    SELECT *, amount/(SELECT Sum(Amount) FROM myTable WHERE counterparty=mytable.counterparty) AS PCSplit
    FROM myTable
    Note you should not use non alphanumeric characters (e.g. %) in table and field names

  5. #5
    wojosh6 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    8
    Thanks for the reply! I created a query using grouping (pretty much the equivalent of a pivot table) by counterparty & linked that back to a second query where I actually perform the calculation. Everything works great. Thanks!!

    Quote Originally Posted by John_G View Post
    The approach I would use would be to make a separate summation query to get the totals for each counterparty, then link that query to the one above on the counterparty ID. You would then use the sum values from that second query to calculate the percentages.

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

Similar Threads

  1. Query to give Subtotals of field
    By dinesh_ltjd in forum Access
    Replies: 2
    Last Post: 01-12-2013, 01:18 PM
  2. Hide Subtotals in Pivot Table
    By Victor70 in forum Forms
    Replies: 2
    Last Post: 04-11-2012, 06:10 AM
  3. Query Subtotals???
    By claysea in forum Queries
    Replies: 3
    Last Post: 02-20-2012, 11:29 AM
  4. Replies: 2
    Last Post: 11-04-2011, 09:14 AM
  5. Subtotals within a query
    By mulefeathers in forum Queries
    Replies: 2
    Last Post: 06-07-2010, 01:02 PM

Tags for this Thread

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