Author |
Topic |
daviss5
Starting Member
2 Posts |
Posted - 2014-03-17 : 13:52:59
|
Good Morning, I am using the query below and it is working great to give me montly averages. I need to find the fiscal year to date averages for the same data. I think all I should need to change is the Select and Group by sections but I am having no sucess.Any help is appricated.SELECT Format([CallDate],"yyyy mmm") AS [Month], Count(DailyCallStats.CallDate) AS CountOfCallDate, DailyCallStats.Agent, Avg(DailyCallStats.Inbound) AS AvgOfInbound, Avg(DailyCallStats.Outbound) AS AvgOfOutbound, Avg(DailyCallStats.TotalCalls) AS AvgOfTotalCalls, Avg(DailyCallStats.AvgWrap) AS AvgOfAvgWrap, Avg(DailyCallStats.ParkTime) AS AvgOfParkTimeFROM DailyCallStatsGROUP BY Format([CallDate],"yyyy mmm"), DailyCallStats.Agent, Format([CallDate],"yyyy mm")ORDER BY Format([CallDate],"yyyy mm"); |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-03-18 : 07:41:52
|
When is your fiscal year?Also, the FORMAT function is very very very very very slow. Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
 |
|
daviss5
Starting Member
2 Posts |
Posted - 2014-03-18 : 11:53:30
|
The fiscal year is April through March. And I am pretty new to SQL so if there is a better way I am open to it. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-03-18 : 17:54:25
|
So January, February and March belongs to the fiscal year the year before? Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-03-18 : 18:02:05
|
Try thisSELECT CallMonth AS [Month], COUNT(CallMonth) AS CountOfCallDate, Agent, AVG(Inbound) AS AvgOfInbound, AVG(Outbound) AS AvgOfOutbound, AVG(TotalCalls) AS AvgOfTotalCalls, AVG(AvgWrap) AS AvgOfAvgWrap, AVG(ParkTime) AS AvgOfParkTimeFROM ( SELECT DATEPART(YEAR, DATEADD(MONTH, -3, CallDate)) AS FiscalYear, DATENAME(MONTH, CallDate) AS CallMonth, DATEDIFF(MONTH, 0, CallDate) AS SortOrder, Agent, Inbound, Outbound, TotalCalls, AvgWrap, ParkTime FROM dbo.DailyCallStats ) AS dGROUP BY FiscalYear, CallMonth, SortOrderORDER BY SortOrder; Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
 |
|
|
|
|