Gary,
The general case of consumption equals the difference between yesterday's
volume and today's volume is simple if you arrange your data well. Let's
assume a list of line items on invoices where products are sold. Some of
the products will sell on some line items of invoices each day. You can't
know which products will sell on a given day and therefore appear as a line
item on an invoice. What you can know is that yesterday's sales are
everything that sold the day before. So, you can query the line item table
for all lines with a sale date of date-1, or DateAdd("d",Date(),-1).
Today's sales are the same query but where sale date = today. If you join
on product then you are assured that you are comparing sales for the last
two days for the same product. Once this view is built, then it's a simple
matter of setting up an expression in the containing view that calculates
consumption = sales_yesterday - sales_today. One other wrinkle, if you want
a comprehensive list of products regardless of whether they sell on a given
day you would need an outer join between product and line item.
You've got to get off the idea that you need 31 or 30 or whatever queries
for each day of the month. Even in the gas tank example the worst case
scenario is a query for each tank/numeric measure. There were about 5
numeric measures, or five columns and 95 tanks. So, the result would have
155 columns if you needed a column per numeric measure & day of the month.
It would have 95 rows, one each for each tank. Jet crosstab queries top out
at 255 columns so this could easily be done as a Jet crosstab without any VB
coding.
--
Alan Webb
kn*******@SPAMhotmail.com
"It's not IT, it's IS
"Gary" <ke*****@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have an example table with fields and records as shown below:
RECORD_ID DATE PRODUCT QUANTITY
1 4/1/05 widget1 50
2 4/2/05 widget1 48
3 4/3/05 widget1 42
4 4/4/05 widget1 28
5 4/5/05 widget1 13
6 4/6/05 widget1 5
. . . .
. . . . (and so on)
30 4/30/05 . .
What I need is an output like this:
DATE PRODUCT SOLD (The quantity from the day before - today's)
4/2/05 widget1 2 (50 - 48)
4/3/05 widget1 6 (48 - 42)
4/4/05 widget1 14 (42 - 28)
4/5/05 widget1 15 (28 - 28)
4/6/05 . .
4/7/05 . .
4/8/05 . .
. . .
4/30/05 . . (and so on)
Calculating the quantity SOLD seems like it would be a common database
task and yet this Newbie can only come up with making 30 queries for
each day of the month. I'm wondering if a VBA module could be made to
loop through these records and perform the calculations...but I'm not a
programmer. Any help would be greatly appreciated!