I have a data set that looks like the following (but obviously much larger):
Date ------------------ Customer ---------- Output
1/01/2016 01:00 ---------- 4 ---------------- 5
1/01/2016 03:00 ---------- 5 ---------------- 20
1/02/2016 09:00 ---------- 4 ---------------- 10
1/04/2016 06:00 ---------- 5 ---------------- 5
1/06/2016 13:00 ---------- 4 ---------------- 10
1/11/2016 23:00 ---------- 5 ---------------- 25
2/10/2016 12:00 ---------- 5 ---------------- 15
2/10/2016 24:00 ---------- 4 ---------------- 25
2/14/2016 16:00 ---------- 4 ---------------- 10
2/16/2016 04:00 ---------- 5 ---------------- 5
2/14/2016 16:00 ---------- 5 ---------------- 10
2/16/2016 04:00 ---------- 4 ---------------- 5
2/18/2016 16:00 ---------- 5 ---------------- 10
2/19/2016 12:00 ---------- 4 ---------------- 5
I need a query that does the following:
1) is able to tell whether the date is on or off-peak, meaning if it is a holiday OR if it falls on the week or weekday
2) if it falls on a weekday, must be able to further break-down on/off peak by hours (1-7 and 24 are off-peak and 8-23 are on-peak)
3) be able to pivot all of that together by month and by average
Basically it would look like this:
Month ----- Cust ------- Year --------- Avg.On-peak ----------- Avg.Off-peak
1 ----------- 4 ------------- 2016 -------------- 10 -------------------------- 7.5
1 ----------- 5 ------------- 2016 -------------- 25 ------------------------ 12.5
2 ----------- 4 ------------- 2016 -------------- 15 -------------------------- 7.5
2 ----------- 5 ------------- 2016 -------------- 12.5 ---------------------- 12.5
I have a linked table to Access from Excel. The data is downloaded from an online database and is stored in excel (but if better to store in Access LMK)
I have tried a switch statement:
For reference [Hrly_Daily_Monthly 2] is a table that just dateparts the datetime_beginning_ept into month, hour, year, etc.
[Off-peak days] is a table of all holidays
Switch(
[Hrly_Daily_Monthly 2].Date=#1/1/2016#, "off-peak day",
[Hrly_Daily_Monthly 2].Date=#5/30/2016# , "off-peak day",
[Hrly_Daily_Monthly 2].Date=#7/4/2016# , "off-peak day",
[Hrly_Daily_Monthly 2].Date=#9/5/2016# , "off-peak day",
[Hrly_Daily_Monthly 2].Date=#11/24/2016# , "off-peak day",
[Hrly_Daily_Monthly 2].Day = 1, "off-peak day",
[Hrly_Daily_Monthly 2].Day = 7, "off-peak day",
TRUE, "on-peak day") AS [On/Off Day]
Get an error because of too many statements.
I also tried creating multiple queries, rather than doing in one, and using the Make Table, to then put all queries together. And it severely slowed the database.
Off-peak day query AKA [off-peak days 2] table
SELECT [Hrly_Daily_Monthly 2].datetime_beginning_ept, [Hrly_Daily_Monthly 2].output, [Hrly_Daily_Monthly 2].cust, [Hrly_Daily_Monthly 2].Date
FROM [Hrly_Daily_Monthly 2], [Off peak list]
WHERE ([Hrly_Daily_Monthly 2].datetime_beginning_ept=[Off-peak days] OR [Day] NOT BETWEEN 2 and 6);
On-peak day query (which is dependent on the off-peak query)
SELECT [Hrly_Daily_Monthly 2].Date, [Hrly_Daily_Monthly 2].cust, [Hrly_Daily_Monthly 2].output,
FROM [Hrly_Daily_Monthly 2]
WHERE NOT EXISTS (Select 1 FROM [Off-Peak Days 2] WHERE [Off-Peak Days 2].Date = [Hrly_Daily_Monthly 2].Date AND [Hrly_Daily_Monthly 2].Date = [Off-Peak Days 2].Date);
any help is much appreciated