Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SELECT
tblSales.ID,
tblSales.Keyword,
DateSerial([lngyear],[intMonth],1) AS MonthYear,
tblSales.sales
FROM
tblSales
ORDER BY
tblSales.Keyword,
DateSerial([lngyear],[intMonth],1);
ID Keyword MonthYear sales
1 ABC 1/1/2010 $10.00
2 ABC 2/1/2010 $10.00
3 ABC 3/1/2010 $11.00
4 CDE 12/1/2009 $100.00
5 CDE 1/1/2010 $90.00
6 CDE 2/1/2010 $110.00
7 CDE 4/1/2010 $115.00
SELECT
CurrentSales.ID,
CurrentSales.Keyword,
CurrentSales.MonthYear,
CurrentSales.sales,
(Select Top 1 monthYear from qrySales where CurrentSales.monthyear > qrySales.monthyear AND qrySales.keyword = currentSales.keyword order by MonthYear Desc) AS PreviousMonth,
(Select Top 1 Sales from qrySales where CurrentSales.monthyear > qrySales.monthyear AND qrySales.keyword = currentSales.keyword order by MonthYear Desc) AS PreviousSales
FROM
qrySales
AS CurrentSales
WHERE ((Not ((Select Top 1 Sales from qrySales where CurrentSales.monthyear > qrySales.monthyear AND qrySales.keyword = currentSales.keyword order by MonthYear Desc)) Is Null));
ID Keyword MonthYear sales PreviousMonth PreviousSales
2 ABC 2/1/2010 $10.00 1/1/2010 $10.00
3 ABC 3/1/2010 $11.00 2/1/2010 $10.00
5 CDE 1/1/2010 $90.00 12/1/2009 $100.00
6 CDE 2/1/2010 $110.00 1/1/2010 $90.00
7 CDE 4/1/2010 $115.00 2/1/2010 $110.00
SELECT
qryCurrentPrevious.ID,
qryCurrentPrevious.Keyword,
qryCurrentPrevious.sales,
qryCurrentPrevious.MonthYear,
qryCurrentPrevious.PreviousMonth,
qryCurrentPrevious.PreviousSales,
[PreviousSales]-[Sales] AS SalesChange,
([PreviousSales]-[Sales])/[PreviousSales] AS PercentChange
FROM
qryCurrentPrevious;
Keyword sales MonthYear PreviousMonth PreviousSales SalesChange PercentChange
ABC $10.00 2/1/2010 1/1/2010 $10.00 $0.00 0.00%
ABC $11.00 3/1/2010 2/1/2010 $10.00 ($1.00) -10.00%
CDE $90.00 1/1/2010 12/1/2009 $100.00 $10.00 10.00%
CDE $110.00 2/1/2010 1/1/2010 $90.00 ($20.00) -22.22%
CDE $115.00 4/1/2010 2/1/2010 $110.00 ($5.00) -4.55%
Public Function getPrevMnth(varDate As Date) As Date
If IsDate(varDate) Then
getPrevMnth = DateAdd("M", -1, varDate)
getPrevMnth = DateSerial(Year(getPrevMnth), Month(getPrevMnth), 1)
End If
End Function
SELECT
CurrentMonth.KeyWord,
CurrentMonth.MonthYear AS CurrentMonth,
CurrentMonth.Sales AS CurrentSales,
[1Prior].MonthYear AS 1MnthPrev,
[1Prior].Sales AS SalesMnthPrev,
[2Prior].MonthYear AS 2MnthPrev,
[2Prior].Sales AS Sales2MnthPrev,
[3Prior].MonthYear AS 3MnthPrev,
[3Prior].Sales AS Sales3MnthPrev
FROM
((tblSales AS CurrentMonth
INNER JOIN
tblSales AS 1Prior
ON
CurrentMonth.KeyWord = [1Prior].KeyWord)
INNER JOIN
tblSales AS 2Prior
ON
[1Prior].KeyWord = [2Prior].KeyWord)
INNER JOIN
tblSales AS 3Prior
ON
[2Prior].KeyWord = [3Prior].KeyWord
WHERE ((([1Prior].MonthYear)=getPrevMnth([currentMonth].[MonthYear]))
AND (([2Prior].MonthYear)=getPrevMnth([1Prior].[MonthYear]))
AND (([3Prior].MonthYear)=getPrevMnth([2Prior].[MonthYear])));