Recently I’ve been working on a small script that gathers information about Jira issues.
We wanted to know the time that a given ticket spends in each column on our kanban board. This can be useful for many reasons: for instance, you can measure the time an issue spent in the Open status to get a ballpark estimate of the average time a ticket is waiting to be assigned. Or you can measure the average time in In Progress to get an idea of velocity in general. You can of course measure any custom status (column) as well.
There is a plugin called the Time in Status for Jira Cloud, which accomplished this purpose. However, if you just want something free, you can hand-roll your custom reporting script like this.
The changelog table represents the state transitions of each issue. How can you use this data for “time spent in column” reports?
If we can somehow get the difference between the timestamps of state transitions of the same issue, then we know that that is the time spent in the given column.
SQL has a handy LAG function for this: it’s a window function that can do calculations on rows based on a given physical offset (which is usually 1). This means that it enables spreadsheet-like calculations based on the row above or below the current one, while partitioning the data into chunks that make sense.
This might be common knowledge, but I didn’t know about this function until a few months ago. Even Julia Evans has tweeted about its usage!
The expression looks like this:
For me to understand what I need to partition by, I ask myself: “What is the entity I want to compare multiple rows for?”. Basically, “Where should the calculation restart”?
In this case, this is the issue_key: since I want to calculate the differences of the timestamp column for the same issue_key.
The query looks like this:
This gives us each ticket’s lifetime in each column.
As you can see, a new “partition” starts with each issue key, and the calculation restarts.
and to always take metrics (especially ones involving human beings) with a grain of salt.
Written on March 1, 2020
If you notice anything wrong with this post (factual error, rude tone, bad grammar, typo,
etc.), and you feel like giving feedback, please do so by contacting me at hello@samu.space. Thank you!