How To Write Queries In Azure Devops

Understanding how to write queries in Azure DevOps isn’t just a technical skill; it’s the secret to maintaining project velocity. In this comprehensive tutorial, I will walk you through everything from basic flat lists to advanced Work Item Query Language (WIQL) syntax.

How To Write Queries In Azure DevOps

Getting Started: The Query Editor Interface

To begin, navigate to your project in Azure DevOps. On the left-hand sidebar, click on Boards and then select Queries as shown in the screenshot below.

how to write queries in azure devops

I always recommend starting with the All tab to see what your teammates have already built. To create your own, click on + New query.

how to create queries in azure devops

Understanding the Anatomy of a Clause

A query is essentially a collection of “clauses.” Each clause consists of four main parts:

  1. And/Or: The logical connector.
  2. Field: The data point you’re looking for (e.g., State, Assigned To, Work Item Type).
  3. Operator: How you want to compare the field to a value (e.g., =, <>, Contains, Under).
  4. Value: The specific criteria (e.g., “Active”, “@Me”, “Bug”).
how to run query in azure devops

Level 1: Writing Flat List Queries

A Flat List is the most common query type. It returns a simple list of work items that meet your criteria.

Common Operators and Their Uses

I always emphasize these essential operators:

OperatorUse CaseExample
=Exact matchState = Active
<>Not equal toWork Item Type <> Task
ContainsPartial text matchTitle Contains "Cloud"
InMatch any value in a listState In (New, Approved, Committed)
Was EverHistorical searchAssigned To Was Ever "Michael Scott"

Using Macros for Dynamic Results

Don’t hardcode your name or today’s date. Use Macros to make your queries “smart.”

  • @Me: Automatically filters for the person running the query.
  • @Today: Filters based on the current date (useful for “Modified Date > @Today – 7”).
  • @CurrentIteration: Dynamically stays updated as your team moves from Sprint 1 to Sprint 2.

Level 2: Advanced Query Types (Trees and Direct Links)

You likely need to see relationships.

1. Tree of Work Items

This is used to view hierarchies. If you want to see all Features and the User Stories nested beneat