Solved

Cumulative (Running Sum) in a query

Posted on 2016-09-17
3
53 Views
Last Modified: 2016-09-17
Experts, I need my query (in the attached sample db) to return a cumulative amount for each tblDraws_Details1.[Amount] ("Draw Amount" as shown in the pic) however in the pic below, you can see I have a 0 in the first row but what I need to return is 1.2B (the amount of the first Draw Amount) and the next row below it in the same column should be $1,200,000,000 + $12,061,706.00
 = $1,212,061,706.00.  What I am looking for is a running sum for tblDraws_Details1.[Amount] and keeping the same where condition: T.FacilityType=Q_Disbursement.FacilityType

How would an expert do this?  I have taken too much time trying to modify.
thank you

I have attached a database.  
Please open the query:  Q_DisbursementSum

screenshotBalanceEE.accdb
0
Comment
Question by:pdvsa
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41803080
try this:
SELECT Q_Disbursement.FacilityType, Q_Disbursement.ValueDate, Q_Disbursement.FacilityAmount, 
(Select Sum(T.Amount) From Q_Disbursement As T Where T.FacilityType=Q_Disbursement.FacilityType And T.ValueDate <= Q_Disbursement.ValueDate)
AS [Cumulative Drawn],
 Q_Disbursement.Amount, [FacilityAmount]-[Amount] AS Available
FROM Q_Disbursement
GROUP BY Q_Disbursement.FacilityType, Q_Disbursement.ValueDate, Q_Disbursement.FacilityAmount, Q_Disbursement.Amount
ORDER BY Q_Disbursement.FacilityType, Q_Disbursement.ValueDate;

Open in new window

0
 

Author Closing Comment

by:pdvsa
ID: 41803107
Perfect.  I am going to look that over and see how you did that.  thats amazing.
0
 

Author Comment

by:pdvsa
ID: 41803112
I see where the edit is:
Old
And T.ValueDate <= Q_Disbursement.ValueDate)-Sum([Amount]) AS [Cumulative Drawn],
Your solution:
And T.ValueDate <= Q_Disbursement.ValueDate) AS [Cumulative Drawn],

I see my old way subtracted the Sum([Amount]) and that is where I was wrong.  

Unfortunately, I will forget what I learned by tomorrow.   :(

thank you for the help Ryan.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question