Results 1 to 6 of 6
  1. #1
    pholt33 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    3

    How do I summarize data from two tables based on multiple criteria?

    I have two tables where I want to combine values based on AccountID and also SecurityID. The first two screenshots are my table setups and the third screenshot is how I ultimately want the data to look.



    What I am trying to get to is a person's current holdings (Shares and Values) based on initial holdings and subsequent transactions. If you think of your personal Vanguard/Fidelity/whatever investment account, I want the summary information that is on the quarterly statements based on the account activity during that time period.

    If it would be possible to combine all the information into a single table rather than having two tables, that would be ideal.

    How can I do this either in a query and/or as a single-table setup?

    Thanks for helping an Access dummy!




    Click image for larger version. 

Name:	Holdings.jpg 
Views:	15 
Size:	54.9 KB 
ID:	14171 Click image for larger version. 

Name:	Trans.jpg 
Views:	15 
Size:	75.4 KB 
ID:	14172

    Click image for larger version. 

Name:	Desired.jpg 
Views:	16 
Size:	90.6 KB 
ID:	14173
    Last edited by pholt33; 10-24-2013 at 03:17 PM. Reason: Fix screenshots

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Your images do not appear to have posted. I don't see any - only red X in their places.
    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.

  3. #3
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Don't try to merge the tables - small tables that have carefully determined relationships is the key to an accurate and useful database.
    Actually, you have too many data fields on the tables.

    There should be another table that links AccountOwner and AccountID, and only the AccountID should be on these tables. Likewise, SecurityID, SecurityType and SecurityName should be in a separate table, and only SecuityID should be on these tables.

    InitialValue is inadequate, and your current value calculation is wrong, accountingwise. You need two fields, InitialBasis and InitialValue. There needs to be a table somewhere that has the current value of any given Security, and currentvalue is number of shares times that, Initialvalue is the number of shares times the current value at the beginning of the period. There needs to be another column, CurrentBasis, for the current accounting cost of the shares remaining at the end of period.
    In fact, you need to determine whether you are using LIFO or FIFO or average basis value, in order to properly determine the basis after any given sale. The drop in Basis needs to be a field calculated at any sale.

    Sorry to give you the bad news, but this structure doesn't do proper tax accounting. If you buy 2000 shares at $10 and sell $1000 shares at $20 the current value ends up zero.

  4. #4
    pholt33 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    3
    I will split the tables tomorrow and then see if I can properly link them back together using only the appropriate/minimum fields required. One I do that in the morning, I'll report back here to figure out the current (or as of a specified date) holdings.

    As far as the specific accounting, that's a minor concern for the purposes of this database. I can probably pull security prices from a separate database, but that can come at a later step.

  5. #5
    pholt33 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    3
    Is this how you would recommend setting up the tables?


    Click image for larger version. 

Name:	TableSetup.jpg 
Views:	12 
Size:	83.1 KB 
ID:	14182

  6. #6
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Mostly. Add a security table with SecurityID as the primary key and SecurityName and securityType as fields. Remove SecurityType from Holdings and Transactions.

    Naming convenstions - I'd suggest putting "tbl" on the front of the names of the tables. Also, since "Date" is a reserved word, I'd suggest HoldingDate and TranDate as better names for the date fields.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-26-2013, 05:08 PM
  2. Replies: 2
    Last Post: 11-04-2012, 02:08 PM
  3. Query for table, based on criteria from other tables
    By PureLoneWolf in forum Queries
    Replies: 2
    Last Post: 10-04-2012, 11:23 AM
  4. Matching based on criteria from multiple tables
    By Jonpro03 in forum Database Design
    Replies: 13
    Last Post: 08-04-2011, 10:29 AM
  5. Update query to summarize multiple values
    By ser01 in forum Queries
    Replies: 3
    Last Post: 05-15-2010, 09:38 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