Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cumulative (Running Sum) in a query

Posted on 2016-09-17
3
Medium Priority
?
61 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 54

Accepted Solution

by:
Ryan Chong earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

971 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