T
Tim Zych
I have a sales table that has rolling totals by week (7 days).
Day 1 sales = day 1 total. Day 2 sales = day 1 + 2, etc. I can figure out a
given day's total by subtracting the prior day total from the current day,
except for day 1 which is always equal to itself.
I need a select query that can breakdown the totals by their daily totals,
not running totals. The approach I was taking was to join tblSales
Here's what I have.
tblSales
Market
SalesDate
Sales
Market and SalesDate is the PK. SalesDate is a date.
tblCalendar
FiscalDay
DayOfFiscalWeek
FiscalDay is a date and is the PK DayOfFiscalWeek has numbers from 1 to 7.
I've tried the following:
SELECT Sales1.Market, Sales1.SalesDate, Sales1.Sales, Sales2.SalesDate,
Sales2.Sales, tblCalendar.DayOfFiscalWeek
FROM
tblCalendar
INNER JOIN
(tblSales AS Sales1
INNER JOIN
tblSales AS Sales2
ON
Sales2.SalesDate=DateAdd("d",1,Sales1.SalesDate) AND Sales1.Market =
Sales2.Market)
ON
tblCalendar.FiscalDay = Sales1.SalesDate
ORDER BY
Sales1.Market, Sales1.SalesDate;
to get to a point where I later can use the DayOfFiscalWeek to subtract the
daily values except for day 1, but this doesn't work. One of the days is
skipped.
Thanks for some help.
Day 1 sales = day 1 total. Day 2 sales = day 1 + 2, etc. I can figure out a
given day's total by subtracting the prior day total from the current day,
except for day 1 which is always equal to itself.
I need a select query that can breakdown the totals by their daily totals,
not running totals. The approach I was taking was to join tblSales
Here's what I have.
tblSales
Market
SalesDate
Sales
Market and SalesDate is the PK. SalesDate is a date.
tblCalendar
FiscalDay
DayOfFiscalWeek
FiscalDay is a date and is the PK DayOfFiscalWeek has numbers from 1 to 7.
I've tried the following:
SELECT Sales1.Market, Sales1.SalesDate, Sales1.Sales, Sales2.SalesDate,
Sales2.Sales, tblCalendar.DayOfFiscalWeek
FROM
tblCalendar
INNER JOIN
(tblSales AS Sales1
INNER JOIN
tblSales AS Sales2
ON
Sales2.SalesDate=DateAdd("d",1,Sales1.SalesDate) AND Sales1.Market =
Sales2.Market)
ON
tblCalendar.FiscalDay = Sales1.SalesDate
ORDER BY
Sales1.Market, Sales1.SalesDate;
to get to a point where I later can use the DayOfFiscalWeek to subtract the
daily values except for day 1, but this doesn't work. One of the days is
skipped.
Thanks for some help.