Solved

Cumulative (Running Sum) in a query

Posted on 2016-09-17
3
33 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 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
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
Comment Utility
Perfect.  I am going to look that over and see how you did that.  thats amazing.
0
 

Author Comment

by:pdvsa
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now