Query - Running Total Help

J

Joe Williams

Hello,

Looking to do a running total in a query, whose base table looks like this:

EMPLOYEEID, TRANSACTIONDATE, AMOUNT
1234, 1/1/2009, $50
1234, 1/1/2009, $10
5555, 2/1/2009, $20
5555, 3/1/2009, $25

I would like the resultant query to display the data as follows:

EMPLOYEEID, TRANSACTIONDATE, AMOUNT, RUNNINGTOTAL
1234, 1/1/2009, $50, $50
1234, 1/1/2009, $10, $60
5555, 2/1/2009, $20, $20
5555, 3/1/2009, $25, $45

So basically the running total resets when the employeeID changes. I have
tried various DSUM functions but have not had any success thus far. Any help
you can provide would be appreciated. Thanks in advance.

Joe
 
R

Ron Weiner

If your table name was named tblRunningTotal then the query below ought to
get you going

SELECT tblRunningTotal.EMPLOYEEID, tblRunningTotal.TRANSACTIONDATE,
tblRunningTotal.AMOUNT,
(Select Sum(Amount) from tblRunningTotal as RT Where rt.Employeeid=
tblRunningTotal.Employeeid and rt.TransactionDate
<=tblRunningTotal.transactiondate) AS xx
FROM tblRunningTotal
ORDER BY tblRunningTotal.TRANSACTIONDATE;

Returns
EMPLOYEEID TRANSACTIONDATE AMOUNT xx
1234 1/1/2009 $50.00 $50.00
1234 1/2/2009 $10.00 $60.00
5555 2/1/2009 $20.00 $20.00
5555 3/1/2009 $25.00 $45.00


Ron W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Lookup value, but between dates 8
grouping error? 8
countif/sumif with multiple variables 5
Query-Report 1
Racking my brain on sumif 4
string crosstab query 1
Help with Distinct 4
Query running sum - help again 2

Top