To query Azure DevOps for stories that were added after the sprint start, you can use the Work Items - Query API with a Wiql query. Here's a step-by-step guide:
Create a Personal Access Token (PAT): If you don't have one already, create a PAT with the necessary permissions (at least 'Work items (read)' scope) in Azure DevOps. You can create a PAT by going to your Azure DevOps profile, clicking on 'Security', and then 'Personal Access Tokens'.
Construct the Wiql query: You can use the following Wiql query to find stories added after the sprint start. Replace [YourProjectName] and [YourSprintName] with the actual names of your project and sprint. The query filters work items based on the 'System.CreatedDate' field and the start date of the sprint.
code
{
"query": "SELECT [System.Id], [System.Title], [System.CreatedDate] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = '[YourProjectName]' AND [System.IterationPath] = '[YourSprintName]' AND [System.CreatedDate] > @Today - 14"
}
The @Today - 14 part of the query assumes that your sprints are two weeks long. Adjust the number of days accordingly if your sprints have a different duration.
Run the query using the API: You can use a tool like Postman or curl to run the query. Here's an example using curl:
bash
curl -u :<your_pat> -H "Content-Type: application/json" -d '{ "query": "SELECT [System.Id], [System.Title], [System.CreatedDate] FROM workitems WHERE [System.WorkItemType] = \'User Story\' AND [System.TeamProject] = \'[YourProjectName]\' AND [System.IterationPath] = \'[YourSprintName]\' AND [System.CreatedDate] > @Today - 14" }' https://dev.azure.com/<your_organization>/<your_project>/_apis/wit/wiql?api-version=6.0
Replace <your_pat>, <your_organization>, and <your_project> with the actual values.
Parse the response: The API will return a JSON response containing the work items that match the query. You can parse the response to extract the information you need. Here's an example of how to parse the response using Python:
python
import json
import requests
response = requests.post(
'https://dev.azure.com/<your_organization>/<your_project>/_apis/wit/wiql?api-version=6.0',
headers={'Content-Type': 'application/json'},
data=json.dumps({
"query": "SELECT [System.Id], [System.Title], [System.CreatedDate] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = '[YourProjectName]' AND [System.IterationPath] = '[YourSprintName]' AND [System.CreatedDate] > @Today - 14"
}),
auth=('', '<your_pat>')
)
work_items = response.json()['workItems']
for work_item in work_items:
print(f"ID: {work_item['id']}, Title: {work_item['fields']['System.Title']}, Created Date: {work_item['fields']['System.CreatedDate']}")
This should help you query Azure DevOps for stories that were added after the sprint start.
Set the query parameters: In the query editor, set the following parameters:
Work Item Type: Set this to "User Story" to filter only user stories.
Team Project: Choose the project you're working on.
Iteration Path: Set this to the sprint you want to analyze. For example, if your sprint is named "Sprint 1," set the iteration path to "YourProjectName\Sprint 1."
Add columns: Click on "Columns" and add the following columns:
ID: This is the work item ID.
Title: This is the user story title.
Story Points: This is the field that contains the story points for each user story. If you're using a custom field for story points, replace "Story Points" with the name of your custom field.
Group by and calculate the average: To calculate the average story points, you need to group the user stories by a common field and then calculate the average. Since we want the average for the entire sprint, we can group by a constant value. Here's how to do it:
Click on "Group by" and select "New Group."
In the "Group by" dropdown, select "Constant."
In the "Value" field, enter any constant value, e.g., "1." This will group all user stories into a single group.
Click on "Add Column" and select "Aggregate."
In the "Aggregate" dropdown, select "Average."
In the "Field" dropdown, select "Story Points" (or your custom field for story points).
Save and run the query: Save the query and give it a name, e.g., "Average Story Points for Sprint." Run the query, and you'll see the average story points for the selected sprint.
Here's an example of the Wiql query you can use if you prefer to use the API:
code
{
"query": "SELECT [System.Id], [System.Title], [Microsoft.VSTS.Scheduling.StoryPoints] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = 'YourProjectName' AND [System.IterationPath] = 'YourProjectName\\Sprint 1' GROUP BY '1' INTO @{AverageStoryPoints=AVG([Microsoft.VSTS.Scheduling.StoryPoints])}"
}
Replace YourProjectName and Sprint 1 with the actual names of your project and sprint. Also, replace Microsoft.VSTS.Scheduling.StoryPoints with the name of your custom field for story points if you're using one.
Work Item Type:
Team Project: Choose the project you're working on.
Iteration Path: Set this to the current iteration. For example, if your current iteration is named "Sprint 5," set the iteration path to "YourProjectName\Sprint 5."
Add a filter for past sprints: To exclude user stories from past sprints, you need to add a filter for the iteration path. Here's how to do it:
Click on "Add filter" and select "Iteration Path."
Set the operator to "Not Under."
In the value field, enter the path to the parent node of all past sprints. For example, if your past sprints are under "YourProjectName\Sprints," enter "YourProjectName\Sprints." This will exclude all user stories that are in any of the past sprints.
Add columns: Click on "Columns" and add the following columns:
ID: This is the work item ID.
Title: This is the user story title.
Iteration Path: This is the field that contains the iteration path for each user story. This will help you verify that the user stories are not in past sprints.
Save and run the query: Save the query and give it a name, e.g., "User Stories Not in Past Sprints." Run the query, and you'll see the user stories that are not in past sprints and are in the current iteration.
Here's an example of the Wiql query you can use if you prefer to use the API:
code
{
"query": "SELECT [System.Id], [System.Title], [System.IterationPath] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = 'YourProjectName' AND [System.IterationPath] = 'YourProjectName\\Sprint 5' AND [System.IterationPath] NOT UNDER 'YourProjectName\\Sprints'"
}
Replace YourProjectName, Sprint 5, and Sprints with the actual names of your project, current iteration, and the parent node of all past sprints, respectively.
Create a new query: In Azure DevOps, navigate to the "Boards" section, then click on "Queries" and "New Query."
Set the query parameters: In the query editor, set the following parameters:
Work Item Type: Set this to "User Story" to filter only user stories.
Team Project: Choose the project you're working on.
Add filters for the time period and state: To filter user stories that are closed within a specific time period and are not in a sprint, you need to add the following filters:
Click on "Add filter" and select "State." Set the operator to "Was Ever" and the value to "Closed." This will include user stories that were closed at any point in time.
Click on "Add filter" again and select "Changed Date." Set the operator to ">" (greater than) and enter the start date of the time period you want to analyze. For example, if you want to analyze user stories closed in the last month, enter a date one month ago.
Click on "Add filter" again and select "Iteration Path." Set the operator to "Does Not Contain" and enter the path to the parent node of all sprints. For example, if your sprints are under "YourProjectName\Sprints," enter "YourProjectName\Sprints." This will exclude all user stories that are in any of the sprints.
Add columns: Click on "Columns" and add the following columns:
ID: This is the work item ID.
Title: This is the user story title.
State: This is the field that contains the state of each user story. This will help you verify that the user stories are closed.
Changed Date: This is the field that contains the date when the user story was last changed. This will help you verify that the user stories were closed within the specified time period.
Save and run the query: Save the query and give it a name, e.g., "Closed User Stories Not in Sprints." Run the query, and you'll see the user stories that are not in sprints and were closed within the specified time period.
Here's an example of the Wiql query you can use if you prefer to use the API:
code
{
"query": "SELECT [System.Id], [System.Title], [System.State], [System.ChangedDate] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = 'YourProjectName' AND [System.State] WAS EVER 'Closed' AND [System.ChangedDate] > '2022-03-01' AND [System.IterationPath] DOES NOT CONTAIN 'YourProjectName\\Sprints'"
}
Replace YourProjectName, 2022-03-01, and Sprints with the actual names of your project, the start date of the time period, and the parent node of all sprints, respectively.
Configure the widget: In the widget configuration panel, set the following parameters:
Title: Enter a title for the widget, e.g., "Custom Field Chart."
Query: Create a query that filters work items based on the custom field you want to analyze. You can use the query editor to set the query parameters, such as the project, work item type, and custom field value.
Chart Type: Choose the chart type that best represents the data, e.g., "Column," "Pie," or "Bar."
Group By: Choose the custom field you want to group the data by. This will create a separate chart series for each unique value of the custom field.
Stack By: If you want to stack the data based on another field, choose the field you want to stack by. For example, you can stack the data by the "State" field to see the distribution of work items by state for each custom field value.
Metrics: Choose the metric you want to display in the chart, e.g., "Count," "Sum," or "Average."
Limit: Set the maximum number of items to display in the chart.
Save the widget: Once you've configured the widget, click on "Save" to add it to your dashboard.
Here's an example of a Wiql query you can use to filter work items based on a custom field named "Custom.Field":
code
{
"query": "SELECT [System.Id], [System.Title], [Custom.Field] FROM workitems WHERE [System.WorkItemType] = 'User Story' AND [System.TeamProject] = 'YourProjectName' AND [Custom.Field] = 'Value'"
}
Replace YourProjectName and Value with the actual names of your project and the custom field value you want to analyze.
Note that the "Chart for work items" widget type is available in Azure DevOps Server 2020 and later versions. If you're using an earlier version of Azure DevOps Server or Azure DevOps Services, you can use the "Query Results" widget type and create a chart manually using a tool like Excel or Power BI.