If you already have brackets in your database, this request is pretty easy. I made the assumption that you didn't, to generate this crosstab query. Here's the layout I assumed for the log table:
Code:
tblCallDetails
CallID Autokey
CallExt Text
CallTime Date/Time
CallType Text Values "LM" or "HU"
Create these two tables and load them with the data as shown. The Bracket Name can be anything you want - after you have it working, you can substitute "12:01AM - 7:00AM" as the name for bracket A, for example. I recommend very short names while debugging and laying out the reports.
Code:
tblBrackets Create records with these values
BrackMin Number 0 7 12 16 17 21 0
BrackMax Number 6 11 15 16 20 23 23
BrackName Text A B C D E F Total
tblSums Create records with these values
SumType Text LM HU Tot
This Crosstab query will then give you the basic layout for your report:
Code:
TRANSFORM Sum(IIF(Q1.SumType = "Tot",1,IIF(Q1.SumType = "LM",
IIF(Q1.CallType = "LM",1,0),IIF(Q1.Sumtype = "HU",
IIF(Q1.CallType = "HU",1,0),0)))) AS TheSum
SELECT
Q1.CallYear,
First(Q1.DispMonth) As CallMonth,
Q1.BrackName
FROM
(
SELECT
Year(TC.CallTime) As CallYear,
Month(TC.CallTime) As CallMonth,
First(Format(TC.CallTime,"mmmm")) As DispMonth,
TC.CallExt AS CallExt,
TB.BrackName As BrackName,
TC.CallType AS CallType,
TS.SumType,
Count(TC.CallType) As CallCount
FROM tblCallLog AS TC, tblBrackets AS TB, tblSums As TS
WHERE Hour(TC.CallTime) >= TB.BrackMin
AND Hour(TC.CallTime) <= TB.BrackMax
GROUP BY
Year(TC.CallTime),
Month(TC.CallTime),
TC.CallExt,
TB.BrackName,
TS.SumType,
TC.CallType
) AS Q1
GROUP BY
Q1.CallYear,
Q1.CallMonth,
Q1.BrackName
PIVOT Q1.[CallExt] & " " & Q1.SumType;
A call that lands by the microsecond exactly onto the hour will go into the wrong bracket, but this gets you pretty close. You could subtract 1 second or 59 seconds from the Calltime in the Year(), Month(), and Hour() calculations, and it would work for those calls.