Using a Group By and Count statement in WIQL (Azure Dev Ops) - azure-devops

I want to make a WIQL query to count the workitems from the type 'Bug', grouped by the title and the software version fields. But, there is no group by function in WIQL. Does anyone have an alternative to make this work in WIQL?
SELECT
[System.Title],
[System.State],
count(*)
FROM workitems
WHERE
[System.WorkItemType] = 'Bug'
AND [System.State] <> ''
GROUP BY [System.Title], [Custom.ToolSoftwareVersion]
The queries are used to create dashboards and overviews, ect.

Does anyone have an alternative to make this work in WIQL?
Based on my experience, the short answer is no.
As you mentioned, GROUP BY and COUNT are not supported currently. More information on the WIQL syntax is available in this document.
Azure DevOps also supports using the WIQL API to query the result. My workaround is that you could query the result as a list, then you could GROUP BY and COUNT the results with our customized code.
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=5.0-preview.2
By the way, you also could give your feedback to the Azure DevOps team.

An alternative approach is to use a "Chart for Work Items" widget that provides a Pivot Table view. You can choose aggregation types such as COUNT, SUM.
This operates similarly to Pivot Tables in Excel with numbers in the output rather than a chart.
Choose Chart Type:
Choose row and column axes
The result is presented as a table with "group by" / count style

Related

How to query datasets by group with CKAN API?

I have managed to create a query to get datasets by tags. For reference I have the following query:
http://localhost/api/3/action/package_search?fq=tags:(my-first-tag%20AND%20my-second-tag)&rows=2
Now, I need to filter these results by the group also. I added a dataset to a group and can see the group as:
http://localhost/api/3/action/group_list
But how can I add the group to the previous query? I can't seem to find anything that works.
You can use the filter query (fq) to search using the group name. For e.g to search the datasets that are in the test group
https://demo.ckan.org/api/3/action/package_search?fq=groups:test-group
To include the two fq, we need to make the query like this:
http://localhost/api/3/action/package_search?fq=tags:(my-tag-1%20AND%20my-tag-2)+groups:my-group-1&rows=2

Azure DevOps reorder work items in query result

Is there a way I can reorder work items from a query results as I would normally do with backlog work items?
I'm using the order of work items in the backlog to set the order of issues to address, I would like to use queries to view work items by certain criteria (cross-project) so the backlog board is not a good choice for me.
thank
The description is little confusing, but if you just want to order your query result(according to the title of this thread) by specific condition, the wiql would be very helpful.
Add the Wiql Editor extension to your organization, then create a query with the other conditions you need, click the "Edit query wiql" and update the query wiql.
For information about wiql syntax, please check Syntax for the Work Item Query Language (WIQL), the order by would be the one you are looking for.

Is it possible to create a rollup column for a query?

I am attempting to create a rollup column for Feature 123 to sum up story points for all User Stories who have Feature 123 as a parent. Furthermore, I would like this rollup column to show up as a query result.
However, I noticed that if I click "Queries", there is no "Add a rollup column". How can I configure Azure DevOps so that the "Add a rollup column" shows up underneath "Add a column"?
Here is some rollup column documentation I've been following.
Add a rollup column feature is not supported for Queries. Please check document here for where Rollup can be used.
Alternatively you can create a flat list query that sums the values of a field you specify as described in above document. Check here for more information about work tracking charts.
You can also submit a feature(Click suggest a feature and choose Azure devops) to Microsoft development team, hope they will consider adding rollup feature to query results.

Creating a VSTS Extension, using WIQL query to grab work item data, can I grab Activity field data?

I'm creating a Visual Studio Team Services extension that in it's current iteration is supposed to display child tasks for development, testing, etc. that were added to a work item. I build a WIQL query to get these tasks and some data about them.
In VSTS (and TFS), tasks have an Activity field, which I want, to differentiate between the different types of tasks (development, testing, etc.). However, I'm finding with the below WIQL query I create, I get the following error: TF51005: The query references a field that does not exist. The error is caused by «[System.Activity]». Is there a way I can get access to the Activity field for those tasks? Or is it just not supported currently?
SELECT [System.Id], [System.WorkItemType], [System.Title],
[System.Activity], [System.State]
FROM WorkItemLinks
WHERE (Source.[System.TeamProject] = 'someProjectID'
AND Source.[System.Id] = someWorkItemID
AND Source.[System.State] <> 'Removed')
AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND (Target.[System.WorkItemType] = 'Task')
MODE(Recursive)
Working through this I discovered https://marketplace.visualstudio.com/items?itemName=ottostreifel.wiql-editor, which has helped make it alot easier debugging my WIQL query. I highly recommend it to anyone who is new to working with WIQL.
You can create a query with necessary fields in web access, then get detail wiql by using Get a query or folder REST API (add $expand=wiql parameter).
I looked some more and discovered my answer, apparently Microsoft.VSTS.Common.Activity is the field you want to reference to get the activity for the task. I found it here: https://www.visualstudio.com/en-us/docs/work/track/query-numeric. Looks like there's some more information there about some data you can grab, like Microsoft.VSTS.Scheduling.StoryPoints. However it's definitely not a complete list, and I wasn't able to find one. Feel free to comment on this if you know of a complete list of references to use to grab anything you want about a work item!

Visual studio online Rest Api query- Get results sorted by a field

I am querying visual studio online API to get a list of work items. The result that I get is by default sorted based on the work item ID. I am trying to get the result sorted by TargetedDate field.
Any idea on how to specify the sort column in the rest query?
Thanks in advance...
I think you might have to build a WIQL query using an ID in (1,2,3) filter and execute it.
That way you can specify sorting as ORDER BY TargetDate.
For example:
POST
https://fabrikam.visualstudio.com/DefaultCollection/Fabrikam-Fiber-Git/_apis/wit/wiql?api-version=1.0
Content-Type: application/json
{
"query": "Select ID From WorkItems Where ID in (1,2,3) ORDER BY TargetDate ASC"
}
More info on the API and WIQL syntax is available on MSDN Docs.
Or....
Just sort it client-side ;)
You need to specify the sort column for the query before use it.
From REST API, update it use the WIQL query as DaveShaw mentioned.
From VSO Web Portal, update the settings for the query from "Column options\Sort Columns", add "Target Date" to "Selected Columns" and select the sort type you want.