Dirk,
Whenever I've needed to do this, I start out with a query that tells
me what the previous production date is for any given date. That way,
if there is no production on a particular date (Sat/Sunday), Mondays
production will be compared to Friday. I used a table (tblProduction)
that contained two fields (ProdDate and ProdQty) for this example.
Query #1(qryPrevDate):
SELECT tblProduction.ProdDate, Max(Previous.ProdDate) AS PrevDate
FROM tblProduction, tblProduction AS Previous
WHERE Previous.ProdDate<[tblProduction].[ProdDate]
GROUP BY tblProduction.ProdDate
ORDER BY tblProduction.ProdDate;
Query #2 then uses Query #1 as an intermediate linking table between
two copies of the production table. I renamed the second instance of
the production table as PrevProduction to eliminate confusion. Use
Left joins between the production table, query #1, and the
PrevProduction table to make sure you get the record associated with
the first production date. If you want to put limits the range of
dates in your report, do that in this query.
SELECT tblProduction.ProdDate
, tblProduction.ProdQty
, qryPrevDate.PrevDate
, PrevProduction.ProdQty AS PrevQty
, [tblProduction].[ProdQty]-[PrevProduction].[ProdQty] AS
Delta
FROM (tblProduction LEFT JOIN qryPrevDate ON tblProduction.ProdDate =
qryPrevDate.ProdDate)
LEFT JOIN tblProduction AS PrevProduction ON qryPrevDate.PrevDate =
PrevProduction.ProdDate;
--
HTH
Dale Fye
Hi, Im (almost desperately) looking for a solution how to
determine the difference between the values in
column/field per record? Inspite of my "search for the
holy grale" no luck yet.
e.g. :
field01 field02 field03
= date = dayly production difference
01/01/01 100 100
01/02/01 152 52 (more produded)
01/03/01 172 20 (more produced)
01/04/01 156 -16 (less produced)..
Thanks a mille for your help.
Dirk