Solved How to Create a Running Total Sum Query in Microsoft Access

Safari

Member
Local time
Today, 15:49
Joined
Jun 14, 2021
Messages
95
Hi All

I Want to Create a Running Balance as Total Sum in Ms Access Query
I Tried Many Times But Not Working

can any one help me and edit the query " Aging" in my attached DB
Query name : Aging

i want new column named NetBalance showing me the running balance for each record in the query
 

Attachments

its not clear for me
still need some help
 
its not clear for me
still need some help
Code:
SELECT TblHeadk.Nz, TblHeadk.da, TblGL.AccId, TblGL.AccName,
 TblGL.cer3, TblGL.deb3, TblGL.des3,
 DateDiff("d",[Da],Date()) AS InvoiceAging,
 nz([deb3],0)-nz(TblGL.cer3,0) AS m00,
 IIf([InvoiceAging] Between 1 And 30,[deb3],0) AS [1-30],
 IIf([InvoiceAging] Between 31 And 60,[deb3],0) AS [31-60],
 IIf([InvoiceAging] Between 61 And 90,[deb3],0) AS [61-90],
 IIf([InvoiceAging] Between 91 And 120,[deb3],0) AS [91-120],
 IIf([InvoiceAging]>120,[deb3],0) AS [Over 120]
FROM TblHeadk INNER JOIN TblGL ON TblHeadk.nz = TblGL.nz1;

Code:
SELECT Aging.da, Aging.Nz,
 DSum("m00","aging","Aging.da<=" & Format(aging.da,"\#mm\/dd\/yyyy\#")) AS sum11, Aging.m00,
 Aging.AccId, Aging.AccName, Aging.cer3, Aging.deb3, Aging.des3, Aging.InvoiceAging,
 Aging.[1-30], Aging.[31-60], Aging.[61-90], Aging.[91-120], Aging.[Over 120]
FROM Aging
ORDER BY Aging.da, Aging.Nz;
daNzsum11m00AccIdAccNamecer3deb3
01.01.2022410900109001020302010101020,0010 900,00
22.02.202231308021801020302010101020,002 180,00
23.02.202272140-59401020302010101025 940,000,00
23.02.202262140-50001020302010101025 000,000,00
 
Personally, my feeling is to find a way to work without this.
A running sum is not how a database works. A database works on the basis of an overall total of the set of records.
As a result it's much easier to use what you can do easily.

A report view will give you a running total easily, so provide that functionality with a report.
 
its not clear for me
If you don't have two monitors, print out the directions and try to follow them using your own table.

I agree with Dave, Running sums do NOT belong in a query. They belong in a report.

And finally, for running sum to work in a query, you MUST have a unique identifier on which to base them. You don't need a unique identifier in a report because the report is a sequential process. One line at a time so it is trivial to keep a running sum. Queries work very differently.
 
Code:
SELECT TblHeadk.Nz, TblHeadk.da, TblGL.AccId, TblGL.AccName,
TblGL.cer3, TblGL.deb3, TblGL.des3,
DateDiff("d",[Da],Date()) AS InvoiceAging,
nz([deb3],0)-nz(TblGL.cer3,0) AS m00,
IIf([InvoiceAging] Between 1 And 30,[deb3],0) AS [1-30],
IIf([InvoiceAging] Between 31 And 60,[deb3],0) AS [31-60],
IIf([InvoiceAging] Between 61 And 90,[deb3],0) AS [61-90],
IIf([InvoiceAging] Between 91 And 120,[deb3],0) AS [91-120],
IIf([InvoiceAging]>120,[deb3],0) AS [Over 120]
FROM TblHeadk INNER JOIN TblGL ON TblHeadk.nz = TblGL.nz1;

Code:
SELECT Aging.da, Aging.Nz,
DSum("m00","aging","Aging.da<=" & Format(aging.da,"\#mm\/dd\/yyyy\#")) AS sum11, Aging.m00,
Aging.AccId, Aging.AccName, Aging.cer3, Aging.deb3, Aging.des3, Aging.InvoiceAging,
Aging.[1-30], Aging.[31-60], Aging.[61-90], Aging.[91-120], Aging.[Over 120]
FROM Aging
ORDER BY Aging.da, Aging.Nz;
daNzsum11m00AccIdAccNamecer3deb3
01.01.2022410900109001020302010101020,0010 900,00
22.02.202231308021801020302010101020,002 180,00
23.02.202272140-59401020302010101025 940,000,00
23.02.202262140-50001020302010101025 000,000,00
IF YOU PLEASE CAN YOU SEND ME THE DB WITH EDIT TO CHECK THE CODES BECAUSE I WANT TO SEE IT HOW IS IT WORKING
 

Users who are viewing this thread

Back
Top Bottom