Create a calculated field showing a percentage

Hi all, I would appreciate it of someone could help me here. I'm completely new to JIRA and have no background as a user. I'm sure what I'm asking is actually fairly simple but I cant get it to work. 

Essentially I have two number fields and I want to create a third which shows a percentage of the two. So simply: 

 

Formula.JPG

 

I have attempted this using a calculated number field and some "script":

<!-- @@Formula: (issue.get("customFieldId=10427") &divide; issue.get("customFieldId=10007") : 0)–>

 

This has not worked and even if it had I'm not sure it would show a percentage anyway.

 

I understand I could use a scripted field which I have the add in to do but I don't know where to start with that.

 

Help much appreciated smile 

 

2 answers

0 vote

Hey there,

I recommend you to use the add-on JIRA Misc Custom Fields to achieve this. Please take a look on their documentation at the following link:

https://innovalog.atlassian.net/wiki/display/JMCF/JIRA+Misc+Custom+Fields

 

--Arthur Gonçalves

Hi Arthur, thanks for this. This is where I actually referenced to do the first attempt at the HTML in my original question. Can you see anything wrong with what I had attempted because its not returning any values: <!-- @@Formula: (issue.get("customFieldId=10427") &divide; issue.get("customFieldId=10007") : 0)–>

try this: <!-- @@Formula: (issue.get("customfield_10427") != null ? issue.get("customfield_10427") : 0) / (issue.get("customfield_10007") != null ? issue.get("customfield_10007") : 0) -->

Hi Sy, that definitely gets values in the field so a step closed I'd say! Not a percentage though, will that have to be done through a scripted field as you have done below? I'll give that a shot

Have you tried using a scripted field? I use that for a lot of calculations, and setting it as a text would allow you to add the % symbol as well.

Its with the Script Runner Plugin: https://jamieechlin.atlassian.net/wiki/display/GRV/Scripted+Fields

Here you can set your custom fields but using getCustomFieldValue("Custom Field Name")

and then perform the calculations you want and then returning the answer, if you need the percentage sign you can set it to return as a text searcher have something like

 

return "% " + answer

Which would end up something like this that you can use:

try{
//Retrieve two dates
w = getCustomFieldValue("Custom Field Name 1")
x = getCustomFieldValue("Custom Field Name 2")

//If Statement to check for nulls
if(w &amp;&amp; x != null){

//Calculating and saving answer
double answer = w/x as double

//displaying(returning) the answer
return answer
}
}
catch(Exception e)
{
}

If you'd like to do this through a post function then a post function is available called "Mathematical or date-time expression calculator " Through the plugin JIRA Workflow Toolbox, here you can calculate as well using different fields.

I'd like to add that the answer I've done is only dividing two fields which contain numbers, if you want to do a percentage calculation then e.g You may calculate something like double difference = w-x as double double division = difference/w as double double answer = division*100 as double return answer this for example will give you the difference between w and x in a percentage.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

220 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you