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

    How to do this calculation

    Hi! I'm trying to implement a prepayment system for my customer orders database. I did this by having an Orders table where I can enter a customer's orders, as well as a Credits table where I can enter a customer's credit payments (a payment of $1000 to be used towards future orders, for example). I have managed to use a Union Query to combine the two into a Transactions query, which shows all orders and credit payments and displays credit payments as positive and orders as negative. This query is sorted by date, from oldest to newest.

    For each customer, I need to be able to find out how much prepaid credit he or she has left to use. The way I see this happening is by having the database go down the Transactions query and keep a running total for the customer's remaining prepaid credit. However, I can't just add up all the credit payments and subtract all the orders, since this would ignore the fact that some orders did not come out of a customer's credit and was paid with cash instead (such as if the customer did not have any credit at the time). I think the running total should go something like this:



    Sn+1 = max{0, Sn+ x}

    where Sn is the running total and x is the next entry in the Transactions query for that customer. This way, if the customer runs out of credit, the running total remains at zero until he adds more credit.

    I am relatively new to Access and I'm wondering if this type of calculation is possible. Will I need to use the Expression Builder or another way of doing it?

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Sounds to me all you need to do is subtract the cash payment from the balance. Credit - Payment - Cash = Balance.?
    If you are trying to get a running total, will this be on a form or a report, or query?

  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,942
    Running sum not necessary just to determine a current balance.

    Do aggregate query that sums the orders.

    Do aggregate query that sums the credits.

    Build query that joins both to the Customers table and construct calculated field that subtracts SumCredits from SumOrders.
    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
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    I did not say it was necessary. The OP said he needed a running total, i.e. running sum.

    rickroller5 Good Luck With Your Project!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,942
    Didn't mean to suggest you did. Just pointing that out to OP because they expressed view that was the way to get current balance. If they really do want running balance that is different issue. Not easily done in query or on form.
    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. Calculation Field in table vs Query calculation
    By Leonidsg in forum Database Design
    Replies: 18
    Last Post: 02-28-2013, 09:38 PM
  2. Calculation
    By buienxg in forum Access
    Replies: 1
    Last Post: 11-16-2011, 07:20 AM
  3. Pay calculation
    By shankar.nst in forum Programming
    Replies: 2
    Last Post: 09-29-2011, 12:15 PM
  4. How to do calculation???
    By latestgood in forum Forms
    Replies: 0
    Last Post: 05-18-2011, 11:11 AM
  5. value calculation
    By kyle in forum Access
    Replies: 3
    Last Post: 03-06-2011, 12:29 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