N
Nicholas Scarpinato
I have an issue with a query and I don't know quite how to tackle it. I'm
building a metrics database for our customer service department, and my
reports are exactly what they're looking for, except when a CSR switches
supervisors in the middle of a reporting period. When this occurs, their
information for the entire month shows up under the current supervisor. I
built a second changelog table to keep track of when the supervisor changes
occur, but I haven't been able to translate those changes over to my report.
I end up with a CSR showing up under both supervisors with the same data.
Here's my query, it's a Make Table query that builds the table the report's
source query is based on:
SELECT tblAgentDataMain.[Agent Name], Format(Avg(IIf(TimeValue([Agent Talk
Time])=0,Null,TimeValue([Agent Talk Time]))),"hh:nn:ss") AS [Talk Time],
Avg(IIf([Average Answered per Hour]=0,Null,[Average Answered per Hour])) AS
AAPH, Avg(IIf([Adherence Percentage]=0,Null,[Adherence Percentage])) AS AP,
Avg(IIf([QA Percent]=0,Null,[QA Percent])) AS QP INTO tblAverages
FROM ((tblAgentDataMain INNER JOIN tblAgentAdherenceMain ON
(tblAgentDataMain.[Agent Name] = tblAgentAdherenceMain.[Agent Name]) AND
(tblAgentDataMain.[Reporting Date] = tblAgentAdherenceMain.[Reporting Date]))
INNER JOIN tblQAMain ON (tblAgentAdherenceMain.[Agent Name] =
tblQAMain.[Agent Name]) AND (tblAgentAdherenceMain.[Reporting Date] =
tblQAMain.[Reporting Date])) INNER JOIN tblATTDataMain ON (tblQAMain.[Agent
Name] = tblATTDataMain.[Agent Name]) AND (tblQAMain.[Reporting Date] =
tblATTDataMain.[Reporting Date])
WHERE (((tblAgentDataMain.[Reporting Date]) Between
fFirstDayInMonth([Forms].[frmReportSelect].[ReportDate]) And
fLastDayInMonth([Forms].[frmReportSelect].[ReportDate])))
GROUP BY tblAgentDataMain.[Agent Name];
fFirstDayInMonth/fLastDayInMonth are functions to generate the first and
last days of the month, respectively:
Function fFirstDayInMonth(dtmdate As Date) As Date
fFirstDayInMonth = DateSerial(Year(dtmdate), Month(dtmdate), 1)
End Function
Function fLastDayInMonth(dtmdate As Date) As Date
fLastDayInMonth = DateSerial(Year(dtmdate), Month(dtmdate) + 1, 0)
End Function
The table that stores the supervisor information is called
tblSupervisorTeamsChangeLog. This table has three fields, "Agent Name",
"Supervisor", and "Starting Date". Whenever the supervisors change their team
members, an INSERT INTO query runs that adds that agent, the new supervisor,
and the current date into the table. I do not have this table linked to this
make table query yet because I've tried three or four different approaches
and none of them yielded the desired results. What I need to be able to do is
pull a report for each agent for a date range of first date to last date of
the month, and be able to split up that data should their be a change of
supervisors during that month. I think my problem is that my expressions to
generate the averages for each field aren't grouping by the dates, they're
just averaging the entire table... can anyone confirm if this is the problem,
and if not, give me some insight as to what I've done wrong?
building a metrics database for our customer service department, and my
reports are exactly what they're looking for, except when a CSR switches
supervisors in the middle of a reporting period. When this occurs, their
information for the entire month shows up under the current supervisor. I
built a second changelog table to keep track of when the supervisor changes
occur, but I haven't been able to translate those changes over to my report.
I end up with a CSR showing up under both supervisors with the same data.
Here's my query, it's a Make Table query that builds the table the report's
source query is based on:
SELECT tblAgentDataMain.[Agent Name], Format(Avg(IIf(TimeValue([Agent Talk
Time])=0,Null,TimeValue([Agent Talk Time]))),"hh:nn:ss") AS [Talk Time],
Avg(IIf([Average Answered per Hour]=0,Null,[Average Answered per Hour])) AS
AAPH, Avg(IIf([Adherence Percentage]=0,Null,[Adherence Percentage])) AS AP,
Avg(IIf([QA Percent]=0,Null,[QA Percent])) AS QP INTO tblAverages
FROM ((tblAgentDataMain INNER JOIN tblAgentAdherenceMain ON
(tblAgentDataMain.[Agent Name] = tblAgentAdherenceMain.[Agent Name]) AND
(tblAgentDataMain.[Reporting Date] = tblAgentAdherenceMain.[Reporting Date]))
INNER JOIN tblQAMain ON (tblAgentAdherenceMain.[Agent Name] =
tblQAMain.[Agent Name]) AND (tblAgentAdherenceMain.[Reporting Date] =
tblQAMain.[Reporting Date])) INNER JOIN tblATTDataMain ON (tblQAMain.[Agent
Name] = tblATTDataMain.[Agent Name]) AND (tblQAMain.[Reporting Date] =
tblATTDataMain.[Reporting Date])
WHERE (((tblAgentDataMain.[Reporting Date]) Between
fFirstDayInMonth([Forms].[frmReportSelect].[ReportDate]) And
fLastDayInMonth([Forms].[frmReportSelect].[ReportDate])))
GROUP BY tblAgentDataMain.[Agent Name];
fFirstDayInMonth/fLastDayInMonth are functions to generate the first and
last days of the month, respectively:
Function fFirstDayInMonth(dtmdate As Date) As Date
fFirstDayInMonth = DateSerial(Year(dtmdate), Month(dtmdate), 1)
End Function
Function fLastDayInMonth(dtmdate As Date) As Date
fLastDayInMonth = DateSerial(Year(dtmdate), Month(dtmdate) + 1, 0)
End Function
The table that stores the supervisor information is called
tblSupervisorTeamsChangeLog. This table has three fields, "Agent Name",
"Supervisor", and "Starting Date". Whenever the supervisors change their team
members, an INSERT INTO query runs that adds that agent, the new supervisor,
and the current date into the table. I do not have this table linked to this
make table query yet because I've tried three or four different approaches
and none of them yielded the desired results. What I need to be able to do is
pull a report for each agent for a date range of first date to last date of
the month, and be able to split up that data should their be a change of
supervisors during that month. I think my problem is that my expressions to
generate the averages for each field aren't grouping by the dates, they're
just averaging the entire table... can anyone confirm if this is the problem,
and if not, give me some insight as to what I've done wrong?