O
Olaf Richter
Hello there,
I use a query to display purchases by origin (PurchOrigin),
seller(CustomerCounter), buyer(PurchCompID)
and quantity during [Start Date] and [End Date].
It is grouped by PurchOrigin, CustomerCounter, PurchCompID and sums the
quantity.
I need the quantity sum of the same period for previous year for each record
in above query
For that I use following subquery
PrevPurch: NZ((Select Sum([Purch]) From tblPurchases
Where PurchOrigin=tblPurchases.PurchOrigin
and CustomerCounter=tblPurchases.PurchSeller
and PurchCompID=tblPurchases.PurchCompID
and tblPurchases.PurchBookDate Between dateadd("yyyy",-1,[Start Date]) And
dateadd("yyyy",-1,[End Date]),0)
It all works fine as long as there is no seller with business in different
origins. Then it sums sales from all origins.
How can I limit the where clause in subquery for PurchOrigin,
CustomerCounter and PurchCompID to particular record in "main" query ?
Any tip is appreciated
Thank you
Olaf
I use a query to display purchases by origin (PurchOrigin),
seller(CustomerCounter), buyer(PurchCompID)
and quantity during [Start Date] and [End Date].
It is grouped by PurchOrigin, CustomerCounter, PurchCompID and sums the
quantity.
I need the quantity sum of the same period for previous year for each record
in above query
For that I use following subquery
PrevPurch: NZ((Select Sum([Purch]) From tblPurchases
Where PurchOrigin=tblPurchases.PurchOrigin
and CustomerCounter=tblPurchases.PurchSeller
and PurchCompID=tblPurchases.PurchCompID
and tblPurchases.PurchBookDate Between dateadd("yyyy",-1,[Start Date]) And
dateadd("yyyy",-1,[End Date]),0)
It all works fine as long as there is no seller with business in different
origins. Then it sums sales from all origins.
How can I limit the where clause in subquery for PurchOrigin,
CustomerCounter and PurchCompID to particular record in "main" query ?
Any tip is appreciated
Thank you
Olaf