DSUM (?) help

unit213

Active Member
Joined
Jul 11, 2003
Messages
427
I'm having trouble creating a running sum in a query in Access 2007. Please see below for a (rudimentary) example of what I'm trying to accomplish. How would I go about doing this in a query?


2w3qfiu.jpg


Any help you can offer would be great.

Thanks.

Dan
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Running totals are not really part of SQL queries generally speaking. You *can* do this in an Access report. You can also push/pull the query to/from Excel and use Excel to do the running total.

I guess if you really wanted to you could also write a short script to fill in the running totals and drop it into a temporary table as a data source.

ξ
 
Upvote 0
Xenou is correct, however I have two workarounds that could be employed. While the data bases that are linked below are not exactly what you are looking for, you can extract the concepts and probably develop your own workaround.

In the checkbook database, I created a running sum in a query that adds up all the ins and outs based upon the date and then in an expression subtracts the withdrawals from the deposits.

In the automileage database, I created an expression that gets the previous mileage for the record preceding the current record. I then create an expression to subtract this value from the new mileage.

Look them over and I am sure you will develop your own workaround.

Here are links to the two files.

http://www.box.net/shared/yhj15r8r9dty6oikfyck

http://www.box.net/shared/yaj30ia91jbfo2c2ehr8

Alan
 
Upvote 0
Thanks for the help Xenou. I appreciate it.

In the checkbook database, I created a running sum in a query that adds up all the ins and outs based upon the date and then in an expression subtracts the withdrawals from the deposits.

First and foremost, that you very much for the sample databases to review. I have a quick question for you. I see your logic in the checkbook database, but can you please explain what the ' Select Nz' statement does (or how it works) in the expression below:

Balance: (select Nz(Sum([Deposits] -[Withdrawals] ),0) from tblTransactions WHERE tblTransactions.TranDate <=tbl.TranDate)

It appears to grab the beginning balance from the tblTransactions table, which is very similar to what I'm looking for. I just haven't seen that before.

Thanks!

Dan
 
Last edited:
Upvote 0
The NZ statement basically says, "if a record in the field shown is null, then take the value after the comma and use that." This ensures that Access can do a calculation. If Access finds a null record then it says that it can't do a calculation. This precludes that from happening. To make the running sum work, you have to create an alias table based upon either a date or a unique id. The select statement here defines the criteria for that.

Look at this link for further explanation: http://www.mrexcel.com/forum/showthread.php?t=358307&highlight=Running+Sums

Alan
 
Last edited:
Upvote 0
The NZ statement basically says, "if a record in the field shown is null, then take the value after the comma and use that." This ensures that Access can do a calculation. If Access finds a null record then it says that it can't do a calculation. This precludes that from happening. To make the running sum work, you have to create an alias table based upon either a date or a unique id. The select statement here defines the criteria for that.

Look at this link for further explanation: http://www.mrexcel.com/forum/showthread.php?t=358307&highlight=Running+Sums

Alan


Thanks again. I'm making good progress. I'll work on this more tomorrow.
 
Upvote 0

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top