Hi, I am having a little trouble with the following problem and was wondering if anyone could help.
I am building a query from several input tables Digital Sales and Daily Sales for a number of retailers, whereby I only wish to incorporate Daily Sales after the date of the latest Monthly Sales report for that retailer (which are all included in Digital Sales).
I currently use several queries to record the date of the latest Digital Sales report for each retailer of the form
This date is given as the 1st of the month for which the report has been supplied.
I then use the following query (with the union select repeated for each retailer)
I have a feeling I am making more of a meal of this than is necessary and would like to streamline this down into a single query if possible.
Any advice would be much appreciated.
I am building a query from several input tables Digital Sales and Daily Sales for a number of retailers, whereby I only wish to incorporate Daily Sales after the date of the latest Monthly Sales report for that retailer (which are all included in Digital Sales).
I currently use several queries to record the date of the latest Digital Sales report for each retailer of the form
Code:
SELECT Max([Digital Sales].[Sales Mth]) AS [MaxOfSales Mth]
FROM [Digital Sales]
WHERE ((([Digital Sales].Source)='RetailerX'));
This date is given as the 1st of the month for which the report has been supplied.
I then use the following query (with the union select repeated for each retailer)
Code:
SELECT [Digital Sales].[Sales Mth] AS [Date], [Digital Sales].Source, [Digital Sales].Account, [Digital Sales].ISBN, Sum(IIf([Digital Sales].[Revenue(£)]<>0,[Digital Sales].[Unit Sales],0)) AS Units, Sum([Digital Sales].[Revenue(£)]) AS Revenue, 'Monthly' AS Which_Database
FROM [Digital Sales]
GROUP BY [Digital Sales].[Sales Mth], [Digital Sales].Source, [Digital Sales].Account, [Digital Sales].ISBN
UNION SELECT [RetailerX Daily sales data].Date AS [Date], 'RetailerX' AS Source, 'RetailerX UK' AS Account, [RetailerX UK Daily sales data].Identifier AS ISBN, Sum(IIf([RetailerX UK Daily sales data].[Shipped COGS]<>0,[RetailerX UK Daily sales data].[Shipped Units],0)) AS Units, Sum([RetailerX UK Daily sales data].[Shipped COGS]) AS Revenue, 'Daily' AS Which_Database
FROM [RetailerX UK Daily sales data], [Latest RetailerX Report]
GROUP BY [RetailerX UK Daily sales data].Date, [RetailerX UK Daily sales data].Identifier
HAVING ((([RetailerX UK Daily sales data].Date)>=First([Latest RetailerX Report].[MaxOfSales Mth])+1+Day(DateSerial(Year(First([Latest RetailerX Report].[MaxOfSales Mth])),Month(First([Latest RetailerX Report].[MaxOfSales Mth]))+1,0))))
I have a feeling I am making more of a meal of this than is necessary and would like to streamline this down into a single query if possible.
Any advice would be much appreciated.