View Full Version : running total calculation?


thepunter
12-19-2001, 10:43 AM
Hi All

I am a complete newbie to access so forgive me if this is too simple for you guys http://www.access-programmers.co.uk/ubb/smile.gif

I want to sum totals within a query.

eg lets say I have a query with the following fields

A B C D

A and B are data fields pulled from a table
C is as calculation on those fields say A*B

D Is where I come unstuck. D I would like to be a running total of the sum of the values in C

for example a sample query out put could look like the following.

A B C D

10 2 20 20
30 1 30 50
15 4 60 110


Any ideas anyone on the statement I should insert in the D column to provide this running total ?

All the best

Mick

Rich
12-19-2001, 01:53 PM
It's easier done at form or report level. Do you really need to do it in a query?

thepunter
12-20-2001, 03:14 AM
Not sure is the honest answer Rich.

At the end of the day the database will be connected to the web via asp. Perhaps the summing would be best done there?

In any case I have figured out how to do it in a query. Not sure if it is the best way but it works so far.

I used another table called stage1 to work out the individual row product eg C in the example above.

In the main query I then used the DSum function to add them up.

Probably horrendus use of a database as viewed by some of the experts round here. It does seem to work however.

I think I had to set up the second table to call from cause of the DSum command structure.

ie DSUM(database,field,criteria)

totalprofit: Format(DSum("[stage1.betprofit]","stage1","[stage1.ID]<=" & [stage1.ID]),"Currency")

Regards

Mick

Rich
12-20-2001, 12:22 PM
Does your table have a sequential ID key field?