Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Expression in a calculated field

Арина
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 8, 2024

Hello!

I need to calculate the percentage of related issues of a certain type and status to the total number of related issues of the same type. And then display the value in the calculated field.

To do this, I need to create an expression in a calculated field, but I don’t understand how to do this at all. 

The formula should look like this:

Number of related tasks with a certain issuetype and status / total number of related tasks with this particular issuetype * 100

 

Help me please :)

2 answers

1 accepted

0 votes
Answer accepted
Арина
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 8, 2024

@Dick 

Thanks, but for me it’s more priority to configure this through an expression rather than through automation

Dick
Community Champion
August 8, 2024

The expression would fill the custom field using automation. 

It would kick-off your calculation and saving the result, keeping it up-to-date for you to enjoy...

more documentation on math expressions available in automation

Dick
Community Champion
August 8, 2024

It's the automation that would gather two arrays of issues that are described in your formula, then using the .size operator you can construct the equation and store the outcome in a similar manner to this:

 

edit issue 

customfield

{{#=}} {{lookupissuesA.size.divide(lookupIsssuesB.size).multiply(100)}}

Like Арина likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 8, 2024

What is the source of information for the expression you show?  A rule may only have one Lookup Issues result at a time, so the above expression cannot work. 

Instead a single lookup issue might be used with smart value, list filtering and a math expression, or repeated lookups could save intermediate results in created variables or with a lookup table.  All of these depend upon which version of Jira (and automation rules) is used, and that information was not provided by the original poster.

Dick
Community Champion
August 12, 2024

Hi Bill, 

So it would be something similar to:

lookupissues = JQL query A

create variable SizeA = LookupIssues.size

 

Lookupissues = JQL query B

create variable SizeB = LookupIssues.size

 

followed by:

 

edit issue 

customfield

{{#=}} {{SizeA.divide(SizeB).multiply(100)}}

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 12, 2024

Yes, that is almost correct.  The variables would need to be converted using asNumber before the inline math operation will work:

{{SizeA.asNumber.divide(SizeB.asNumber).multiply(100)}}

 

Although for this scenario, I instead recommend using smart value, list filtering with a math expression as it only requires one read of the issues from the database.  When the issues gathered or the JQL are very different, the multiple calls to Lookup Issues seems better.

 

For example, this would produce the percentage completed by story points:

{{#=}}ROUND( ( 0{{#lookupIssues}}{{#if(equals(status.statusCategory.name,"Done"))}}+{{Story points|0}}{{/}}{{/}} ) / {{lookupIssues.Story points.sum|0}} * 100, 0){{/}}

How that works, working from inside to outward...

  • iterate over the lookup results
  • using a conditional filter to check if the status is a "Done" one
  • and if so, add the story points, with a default of 0 for issues with no value
  • with a leading 0 and surrounding parentheses to sum the values
  • that is then divided by the total story points for the issues in the lookup result
  • which is multiplied by 100 and then rounded to create a whole number percentage
  • finally wrapping everything in a math expression

Additional criteria could be added using the other conditional logic functions.

0 votes
Dick
Community Champion
August 8, 2024

Hi Arina,

You can use an automation to do the math for you.

the lookup issues can be referenced using .size as is given in the Atlassian documentation

Suggest an answer

Log in or Sign up to answer