Community Announcements have moved! To stay up to date, please join the new Community Announcements group today. Learn more
×Estimated time to read: 6 minutes
TL;DR: Community members often ask how to calculate a percentage complete value, such as for an Epic's child items. This article outlines one approach using a single Lookup Work Items action, and potential challenges to manage with the rule.
Jira Cloud does not have a general purpose, built-in feature to calculate fields for customers. In some features, application code is used to calculate things such as percentage completed for a set of work items. Unfortunately, those values cannot always be accessed directly, such as in JQL searches, dashboards, etc.
Automation rules provide a workaround for this...provided one considers potential edge cases and challenges. We will cover those at the end of this article.
We will use the Lookup Work Items action with JQL to gather the work items. In our case, we are looking for the sibling, child work items of an Epic.
Thus, an example rule to update an Epic's custom field Percentage Complete when a child work item transitions status would be this:
parent = {{issue.parent.key}}
{{#=}}ROUND( ( 0{{#lookupIssues}}{{#if(equals(status.statusCategory.name,"Done"))}}+1{{/}}{{/}} ) / {{lookupIssues.size|0}} * 100, 0){{/}}
How that works is:
That will calculate the percentage by count of items. When instead one wants the percentage by the Story Point values, substitute that field to find the sums rather than the counts.
{{#=}}ROUND( ( 0{{#lookupIssues}}{{#if(equals(status.statusCategory.name,"Done"))}}+{{Story points|0}}{{/}}{{/}} ) / {{lookupIssues.Story points.sum|0}} * 100, 0){{/}}
Several things could impact the accuracy of the percentage complete. One needs to either: create multiply rules to calculate the value, or use a single rule with a Scheduled Trigger to periodically calculate the value. Those cases include at least these:
Some of these cases may be combined to reduce the number of rules.
Lookup Work Items can only return up to 100 items. The REST API endpoint used by rules has this limit, with no workarounds, except...
The new search endpoint supports up to 5000 items, but it can only return the ID value for anything more than 100 work items. A work around would be to change the rule to use the Send Web Request action to call the endpoint twice:
This edge case is a bit extreme; when you want a percentage for this many items, consider instead using marketplace apps or advanced planning features of Jira.
What if I want to calculate the percentage values at multiple work item levels, such as Subtasks to Story, Story to Epics, etc.?
Since the changes to use the Parent field for parent / child relationships, the rule could be modified to handle any such pairing of types. And, the rule trigger could be modified to allow rule trigger, so the percentage updates could cascade. There are two more things to note when this is attempted:
Thank you for reading all the way to here! Hopefully you learned some new automation ideas. Please let me know your feedback and improvement ideas for the article, and as always...
Happy rule writing!
Bill Sheboy
agile coach, idling
None
Atlassian Community
3,112 accepted answers
0 comments