Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Calculating Profit Total -- Help!!

Author  Topic 

Papa
Starting Member

5 Posts

Posted - 2004-08-23 : 19:13:24
I have a field called ProfitToDate (currency) and a field called Profit. Each record will have a dollar/cent amount posted in the Profit field. I want the ProfitToDate field to be updated for each record. In other words, I want the ProfitToDate field to show the totaled amount of the Profit field for all preceding records and the current record. How do I calculate this in my form design? Please give an example and keep it simple. I’m new at this stuff.

Thanks very much.

Papa

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-08-23 : 19:21:46
It's better not to store this information directly in the table. You would be better off creating a query that contains this field rather than re-calculating every time you enter a record. Bear in mind that you'll have to update the value for deletions, updates etc etc.

Go to Top of Page

Papa
Starting Member

5 Posts

Posted - 2004-08-23 : 19:39:59
Thanks for the advice. Can you post an example of a query for this situation that I could use for a template? I'm rather new at this.

Thanks,
Papa
Go to Top of Page

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-08-23 : 19:45:59
Something like this:
SELECT T.ID, T.field1, T.field2, T.Profit, (SELECT Sum(Profit) FROM myTable WHERE ID <= T.ID)
FROM myTable T

should do the trick. If you can't adapt this to what you're doing, post your table designs and some sample data for us to have a look at.
Go to Top of Page
   

- Advertisement -