How to Sum and Subtract Story Points of Issues with Certain Status
Asked by cjohns:

I feel like I'm very close with this automation, but still haven't been able to quite figure it out. I'm wanting to track the total story point estimates of all issues in a "To Do" status that pertain to the same story by having that total number in a field of the story.

With this automation I've created below, I'm able to sum all the story point estimates of my issues in the "To Do" status, however, when the status changes to "Done", the sum doesn't change.

I'm wanting to track the total amount of story point estimates we have left for a project in a way that when an issue is marked as "Done" its story point estimates won't be included with the total left to do in order to finish the project as a whole. This is what I've put together so far,

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/190987i89598C065868D853/image-size/large?v=v2&px=999 "image.png")

Below is each automation section mentioned above expanded

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/190988i5F7C588D6FCBCECC/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/190989i73C1C9E5687F39D3/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/190990i3E455BB623364ED8/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/190991i2DC8A386AE97F6ED/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/190992iE64F5D67B30B8058/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/190993i6B0C5FCAEA303874/image-size/large?v=v2&px=999 "image.png")

With this automation in place, it calculates the total story points I have in the To Do status and inputs that total to the linked story of the issues as shown below in the Child Story Points Left TO DO.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/190994i8D426A0CC1308631/image-size/large?v=v2&px=999 "image.png")

Once I change one of those issues to a "Done" status, the total still shows as 20. I want that total to adjust and not count the issue that is now Done.

Any help to this would be great! If I need to change this automation or if I need to create another automation as well that will do the subtraction that would work too. Any and all help would be appreciated.

Thank you,


Answers:
author: Bill Sheboy
body: Hi [@cjohns](/t5/user/viewprofilepage/user-id/4843861) -- Welcome to the Atlassian Community!

If I understand your use case, for any linked issues, you want to sum the remaining (non-done) story points into a custom field...regardless of the issue type hierarchy. And, this means that the same story points could be summed in multiple different issues (due to bidirectional linking). Please let me know if I am misunderstanding your use case.

The condition in your rule which checks status = To Do is halting further processing. There are a couple of ways to solve this:

1. Whenever story points or status change, update the summed custom field no matter what the fields change to, and use a Lookup Issues action with JQL to limit the values to sum based on status rather than a branch approach and repeated/nested link access.
2. Modify your rule to use the if/else condition structure, using different actions for the different status values

I recommend #1 as you are more likely to have accurate results, easier testing, and easier maintenance for future changes.

Kind regards,  
Bill

comments: author: cjohns
body: Thanks for your response. If I'm understanding your clarification correctly, I do want to keep the issue type hierarchy meaning that if I have four issues that all together total 20 story point estimates and those same four issues are linked to Story 1, then Story 1 should show "20" under the custom field.

I am new to Jira and have been reading a lot on automation and how to understand it more, but I don't quite know how I would put what you are saying into practice. It makes sense what you are saying, but I don't know how to translate that to the automation.

This is what I put together, but I'm missing something to have it only sum up "To Do" tasks and remove the task if it is changed to a "Done" status.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/191014iD0A0FD1D49E6E4AA/image-size/large?v=v2&px=999 "image.png")

I'm not completely sure what I need to add or change from this to sum it up to the linked story.

Thanks again for all your help!


author: Bill Sheboy
body: Thanks for that information, [@cjohns](/t5/user/viewprofilepage/user-id/4843861)

**I am still unclear what problem you would be solving with this use case**, as there could be an interlocking tree of linked issues, and so that summed story points field may not be meaningful. It may be safer to only sum values for a parent issue to children, and I suggest considering that approach and discussing with your site admin before proceeding.

Anyways...

One **TODO**: please consider what to do with this custom field when an issue completes/moves to done: should it stop updating or continue to update or be cleared. After you decide that you may update the rule(s).

You will also need a rule triggered on changes to issue links, so I recommend *three rules to reduce the amount of duplication*:

1. Triggered on change to Story Point Estimate or Status, and add a special comment to tell rule #3 to run
2. Triggered on change to Issue Links, and add a special comment to tell rule #3 to run
3. This rule will perform the actual summation of the story points and update the custom field. In the details of this rule, enable the "Allow Rule Trigger" option so rules #1 and #2 can trigger it.

Such a rule #3 would be close to what you have done:

* trigger: detect the special comment was added with a trigger and a condition test
* condition: issue type is Story, Task, or Subtask (assuming you are not sizing Bugs)
* **TODO ITEM FROM ABOVE** :
  * edit the trigger issue, based on your decision: clear the field, or set it with...
  * use the lookup issues action with JQL to gather your open, linked issues AND the trigger issue: issueType IN (Story, Task, Subtask) AND statusCategory != Done AND (issue IN linkedIssues( {{triggerIssue.key}} ) OR key = {{triggerIssue.key}} )
  * action: edit the trigger issue custom field, for the sum of story points, {{lookupIssues.Story point estimate.sum\|0}}
* branch: on linked issues
  * action: use lookup issues to gather their open, linked issues with JQL:
  * issueType IN (Story, Task, Subtask) AND statusCategory != Done AND (issue IN linkedIssues( {{issue.key}} ) OR key = {{issue.key}} )
  * action: edit to set the custom field, for the sum of story points, {{lookupIssues.Story point estimate.sum\|0}}

Please note: this will be a slow rule to process and could in fact fail if multiple issues update in a short window of time. For example, at the end of a sprint or rapidly moving things on the board.


Tags: story-points