Field calculations

JohnWard1947

New member
Local time
Today, 06:23
Joined
Feb 25, 2005
Messages
6
I am recording data (Totals) on a monthly basis using one row per month. I would like to be able to subtract the results of the previous month's field from the latest to give the difference. ie This month's recorded total hours run is 1566 - last month's recorded hours run is 720 - difference is 846. How can this be done?

Thanks
John
 
Your choice of words tells me you migrated from Excel/other spreadsheet to get to Access. You need to do a paradigm shift if that is so. You are still thinking "flat-file" and that isn't Access. However, be that as it may, there are ways to do what you want and never let it be said we would blow you off just 'cause of your choice of words.

It is not clear in what form you are storing your data so I'm going to be less than perfectly lucid in my answer. If I take you literally, you have a record with some sort of date field and a number. What you want is a computation of the difference between successive months.

The way to do this, in overview, is to compute the values of whatever month/year key you are using for the date field. Do it for the month in question and the month prior to that one. Then you can subtract the stored values, perhaps at worst via two DLookup calls. I have seen topics on "running totals" but to be honest, this appears to be different. You want a running difference, and that is trickier. I think GHudson has published a couple of articles on the topic but I can't recall what keyword you would use to search for it other than his name.

If you tell us what form your date takes in your table, one of us might be able to give you a more specific answer as to exactly how to do this. Like, do you have year/month as a string, or short-date of the 1st of the month, or long-date of the last day of the month, or some encoded time-tag format? That sort of thing.

OK, now the "lesson" side of this to help you shift paradigms...

If all you are storing in your DB is this total once per month, you should not have left the spreadsheet. You don't need Access for this class of operation. And Excel can do this very conveniently. On the other hand, if you are trying to upgrade, you are going to give up some things in order to gain some other things.

For instance, if you are storing ALL of the contributors to the monthly total as well, you can just directly compute the monthly sums (that should equal your monthly incremental difference) in a query - and NEVER have to actually store the total. This is done by a Summation query over your detail records grouped by year/month, which you can do as the concatenation (using & operator) of two calls to a DatePart function. Or the query wizard can build a summation query with year/month GroupBy for you, if I recall it correctly. (HINT: Sometimes the Access wizards are your friends DESPITE their being dumber than a box of rocks. Because at least they give you a good starting point that you can then customize.)

You should NEVER EVER store a field that can be recomputed on-demand from other data in your tables. Storing computed data violates one of the principles of normalization, which therefore relates both to the accuracy and the efficiency of your data storage.
 
Thanks for that. Yes, this was originally an Excel spreadsheet report that was starting to grow in width with many columns. I just thought that the info could be more easily entered using a form and presented using an Access report format.

Perhaps I should remain with Excel and be a bit more inventive with my data input and presentation etc.

Cheers
John
 
Basically, what you should consider is a cost/benefit analysis. (Jeez, for MY little project...???) Yes, even for small projects.

Access is incredibly powerful but isn't designed for the same thing that Excel was designed to do.

At base, Excel is an accountant's ruled analysis pad. In Excel, POSITION is all-important. I.e. data appears in rows, one on top of the other, and formulas can compute the difference between "current" and "previous" rows. Because Excel is designed to take advantage of positional stuff like that. Where Excel starts getting more difficult and obscure is when you want to do something that "breaks" the positional nature of the data being entered. I.e. searches within rows, searches across columns, various kinds of variable formatting, etc. etc.

Access, on the other hand, does not consider "position" to mean the same thing. Position is like the Red Queen's dictionary in Wonderland.... It means what I want it to mean! Position isn't defined until sort order is defined, and if no such definition exists, position has no meaning - or worse, totally unpredictable meaning. So to "take the difference of successive rows" is a tough nut to crack.

If this is all you wanted to do, you probably would do better with Excel. If you wanted to convert the entire schmeer, detail data and all reports, to Access, now you are talking about a possibly reasonable return on your development investment.
 
Field Calcs

I think you've convinced me! I'll stick to Excel for this one.

John
 

Users who are viewing this thread

Back
Top Bottom