Skip to content

Instantly share code, notes, and snippets.

@evakili
Created April 29, 2018 12:56
Show Gist options
  • Save evakili/708021d98b915a8563ebf69b7e22d014 to your computer and use it in GitHub Desktop.
Save evakili/708021d98b915a8563ebf69b7e22d014 to your computer and use it in GitHub Desktop.
This is a simple query to calculate average cycle time per team project from Team Foundation Server data warehouse.
Declare @from date;
Declare @initial_state nvarchar(256);
Declare @final_state nvarchar(256);
Set @from = DATEADD(year,-1,GETDATE());
Set @initial_state = 'Committed';
Set @final_state = 'Done';
With wi As (
Select TeamProjectSK, System_Id, System_State, System_ChangedDate, System_WorkItemType
From [Tfs_Warehouse].[dbo].[DimWorkItem]
Where
System_WorkItemType in ('Bug', 'Product Backlog Item')
and System_ChangedDate >= @from
and System_State in (@initial_state, @final_state)
)
Select P.ProjectPath, C.[Cycle Time]
From DimTeamProject P
inner join (
Select D.TeamProjectSK, Avg(D.Duration) [Cycle Time]
From (
Select w1.TeamProjectSK, w1.System_Id, DateDiff(day, w1.ChangedDate, w2.ChangedDate) as Duration
From (
Select TeamProjectSK, System_Id, Min(System_ChangedDate) ChangedDate
From wi
Group By TeamProjectSK, System_Id, System_State
Having System_State=@initial_state
) w1
inner join (
Select TeamProjectSK, System_Id, Max(System_ChangedDate) ChangedDate
From wi
Group By TeamProjectSK, System_Id, System_State
Having System_State=@final_state
) w2
On w1.System_Id=w2.System_Id
) D
Group By D.TeamProjectSK
) C
On C.TeamProjectSK=P.ProjectNodeSK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment