Results 1 to 4 of 4
  1. #1
    esk10 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    2

    Keeping a Running Total if the Same Type

    Hello! I'm trying to build a query that keeps a running total up to a certain date for each query entry if it is in the same type.

    I have built a simple table that illustrates my case:
    ID Date Amount Type1 11/14/2012 100 A
    2 11/22/2012 200 A
    3 11/23/2012 300 B
    4 11/26/2012 200 A
    5 11/29/2012 400 B


    I have created a query with DSum to keep a running total; however I need the running totals to be different based on type. Currently I have this:


    ID Type Year MonthDay RunTot
    1 A 2012 11 14
    2 A 2012 11 22 100
    3 B 2012 11 23 300
    4 A 2012 11 26 600
    5 B 2012 11 29 800

    As you can see, the running total does not consider the type into account.

    The current RunTot (Running Total) query function is:
    RunTot: DSum("Amount","Orders","DatePart('m', [Orders]![Date] )<=" & [Month] & "And DatePart('yyyy',[Orders]![Date])<=" & [Year] & "And DatePart('d',[Orders]![Date])<" & [Day] & "")

    Is there a way to fix this in access query? I've been working on this the whole day but without success.

    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    This is what reports are for. Build report using its Grouping & Sorting with aggregate calcs in group Header/Foother. This will allow display of detail records and summary calcs.

    Otherwise, review http://allenbrowne.com/subquery-01.html
    especially the example for Aggregation: Counts and Totals
    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
    esk10 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    2
    Thank you for the reply.

    True - creating a report will give me those numbers; however, I need to use the running total numbers to calculate something else.

    The data provided above is actually a dummied down version that I created for this forum. The actual data involves investment securities. Portions of the securities are disposed. I need to figure out the interest earned at each disposal date. The problem is that at each disposal date, I need to figure out the outstanding amount of the security (the portion that we haven't sold back) so that I can use that amount, multiply by the interest rate to get the interest earned.

    I'm not familiar with subqueries and SQL (I usually just use the design view access), so I will need some time to look through the link you've provided.

    Any thoughts on this situation? Thank you!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Try including the Type field in the DLookup as another criteria.

    Domain aggregate functions can cause queries to run slow but that's the only other way I can see to get what you want.
    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. Running Total Query??
    By kwooten in forum Queries
    Replies: 8
    Last Post: 06-15-2012, 06:10 AM
  2. Running Total (Cumulative)
    By jamesborne in forum Queries
    Replies: 3
    Last Post: 12-26-2011, 09:30 PM
  3. running or sub total using sql query in access
    By learning_graccess in forum Access
    Replies: 4
    Last Post: 10-15-2011, 05:40 AM
  4. Running total
    By lololthis in forum Queries
    Replies: 5
    Last Post: 06-21-2011, 04:14 PM
  5. Running Total in Subform
    By Scorpio11 in forum Forms
    Replies: 19
    Last Post: 07-03-2010, 05:44 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