How to: Group or Ungroup Work Item Query Clauses

By grouping query clauses, you specify that those clauses should be evaluated as a single unit within the rest of the query. When you group multiple clauses, the effect is the same as if you put parentheses around an expression in a mathematical equation or logic statement. When you group clauses, the AND or OR for the first clause in the group applies to the entire group. As the following table shows, the grouped clauses are translated into the corresponding logical expression. The first expression returns all priority 1 work items and all active bugs. The second expression returns all active priority 1 work items and all priority 1 bugs, whether they are active or not.

Grouped clauses

Logical expression

OR Operator with Grouped AND Clause

Priority=1 OR (Work Item Type=Bug AND State=Active)

AND Operator with Grouped Or Clause

Priority=1 AND (Work Item Type=Bug OR State=Active)

Note

You cannot create a work item query that returns a set of linked work items. However, you can create a Microsoft Excel report that connects to the SQL Server Analysis Services cube, which lists linked work items. For more information, see How to: Create a Report in Microsoft Excel for Team System and the following page on the Microsoft website: Understanding the TFS Cube.

Required Permissions

To perform these procedures, you must be a member of the Readers group or have the View work items in this node permission set to Allow. To save a query as a team query, you must be a member of the Project Administrators group. For more information, see Team Foundation Server Permissions.

To group work item query clauses

  1. Right-click the query you want to edit from the Team Queries or My Queries folders, and select View Query.

  2. In the query, select the query clauses that you want to combine into a group by clicking the left-most cell in the rows. Press CTRL and click to select multiple rows.

  3. Right-click the selected clauses, and then click Group Clauses.

    A bracket appears in the left margin of the query showing that the clauses are grouped.

  4. Save the query.

To ungroup work item query clauses

  1. Right-click the query you want to edit from the Team Queries or My Queries folders, and select View Query.

  2. In the query, select the entire grouped query clauses that you want to ungroup by clicking the left-most cell in the rows. Press CTRL and click to select multiple rows.

  3. Right-click the group, and then click Ungroup Clauses.

    The bracket is removed from the left margin of the Query Builder and the clauses are ungrouped.

    Note

    If Ungroup Clauses is unavailable, you have not selected all the clauses in the query grouping. Select all the clauses and try again.

  4. Save the query.

See Also

Tasks

How to: Save Work Item Queries

How to: Add or Remove Work Item Query Clauses

How to: Add New Work Item Queries

How to: Run Work Item Queries

Concepts

Working With Work Item Queries

Change History

Date

History

Reason

August 2010

Added examples of how a grouped clause is logically evaluated and information about querying for linked work items.

Customer feedback.