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

    Running Sum by Date criteria in a query

    Hello!


    I want to running sum with Date and CustomerID criteria. My data is something like this;

    CustomerID VDate Debit
    1 30-06-12 50,000.00
    1 02-07-12 6,400.00
    1 02-07-12 24,030.00
    1 02-07-12 63,750.00
    2 03-07-12 2,072.00
    2 04-07-12 17,480.00
    1 05-07-12 3,625.00
    1 11-07-12 2,560.00
    1 11-07-12 4,080.00

    I want running sum of current field for all previous date debit fields for customerID. I don't know how to do this, moreover there is also problem of duplicate dates. Because duplicate date can cause problem while summing the older date fields if the current date is also same.
    I look forward to any assistance.

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    This thread describes a technique I have used for creating a running sum in a checkbook. You may have to add the record number ID (hopefully an autonumber) to the mix.

    http://www.mrexcel.com/forum/microso...l-records.html

    Alan

  3. #3
    inno is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    4
    Thanks for your help.
    After going through the thread, i could not find solution for my problem. In my case i want a running sum in query by the vDate field for a perticular account ID but i fail. I can easily get running sum by the transaction ID, but when i add a new record in back dates, it just gives running sum on the basis of transaction id. Another thing, for instance if i succeed getting running sum by date, i don't know what to do with duplicate dates.



    Quote Originally Posted by alansidman View Post
    This thread describes a technique I have used for creating a running sum in a checkbook. You may have to add the record number ID (hopefully an autonumber) to the mix.

    http://www.mrexcel.com/forum/microso...l-records.html

    Alan

  4. #4
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    In my checkbook program which calculates on the dates, if there is more than one date, then the result is the same for all records having the same date. This is not an issue for me. If there are duplicate dates, what would you like Access to do about it?

    Here is another solution, but I don't think it will solve your issue with the duplicate dates. You will need to resolve in your mind, which is more important to you. Dates or Transactions. Without some substantial VBA which would loop through your recordset and characterize your data based first on date and then on transaction ID, I am not sure that there is an alternative solution.
    http://www.datapigtechnologies.com/f...unningsum.html

    Alan

  5. #5
    inno is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    4
    Thanks allot.
    Actually i am working on A/R Aging report. For the purpose i need running sum based on date fields than by using IIF statement i can apply the payments, but i m just wandering around the running sum. I can get the running sum in report directly but i can not sum up in the footer as calculated fields can not be sum up. That is why i have to do it through query. Currently i get running sum through this
    RunningSum: CCur(Nz(DSum("[Debit]","[Debit]","[CustomerID] =" & [CustomerID] & " AND [IDtrans] < " & [IDtrans] & ""))).
    IDtrasn is the auto-number for Debit table. There is a field vDate in Debit table, that i want to include in the above Dsum function, or there may be some other best way to do it.


    Quote Originally Posted by alansidman View Post
    In my checkbook program which calculates on the dates, if there is more than one date, then the result is the same for all records having the same date. This is not an issue for me. If there are duplicate dates, what would you like Access to do about it?

    Here is another solution, but I don't think it will solve your issue with the duplicate dates. You will need to resolve in your mind, which is more important to you. Dates or Transactions. Without some substantial VBA which would loop through your recordset and characterize your data based first on date and then on transaction ID, I am not sure that there is an alternative solution.
    http://www.datapigtechnologies.com/f...unningsum.html

    Alan

  6. #6
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Help me to understand what goes in the footer? I cannot understand how you would use a running sum in a footer? Try to explain in business terms what you are attempting to accomplish.

  7. #7
    inno is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    4
    Dear alansidman'
    I just want to have a running sum in query for table Debit, i m using the following running sum formula

    RunningSum: CCur(Nz(DSum("[Debit]","[Debit]","[CustomerID] =" & [CustomerID] & " AND [vDate] < " & [vDate] & "")))

    But it is not working. My purpose is to obtain sum of Debit for all the smaller than the current date field, something like this

    CustomerID VDate Debit RunningSum
    1 30-06-12 50,000.00 0
    1 2/7/2012 6,400.00 50,000.00
    1 2/7/2012 24,030.00 56,400.00
    1 2/7/2012 63,750.00 80,430.00
    2 3/7/2012 2,072.00 0
    2 4/7/2012 17,480.00 17,480.00
    1 5/7/2012 3,625.00 144,180.00
    1 11/7/2012 2,560.00 147,805.00
    1 11/7/2012 4,080.00 150,365.00





    Quote Originally Posted by alansidman View Post
    Help me to understand what goes in the footer? I cannot understand how you would use a running sum in a footer? Try to explain in business terms what you are attempting to accomplish.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-21-2012, 03:05 PM
  2. Running Query on only 1 row of table.. Criteria?
    By JMac in forum Database Design
    Replies: 5
    Last Post: 04-16-2012, 11:27 PM
  3. Query using Date() criteria
    By Bruce in forum Queries
    Replies: 27
    Last Post: 01-30-2012, 01:15 PM
  4. Prompt User for Date Range when running QUERY
    By taimysho0 in forum Programming
    Replies: 3
    Last Post: 01-30-2012, 11:49 AM
  5. Replies: 10
    Last Post: 11-06-2011, 01:30 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