Calculating percentage based on picklist


I have a project with about 2 dozen custom fields that have a string values such as:


Fail - reason 1

Fail - reason 2

Fail - reason 3


I need to calculate the total percentage of passes on every issue within this project. The variations of fail do not matter I just need to calculate the total number of passes received against the total number of fields. 

I am very new to the reporting/admin side of JIRA and have found how to do things similar when dealing with custom fields that have numeric values, but I have picklist string values that must be used for this project. 


Can someone point me in the right direction?



2 answers

1 accepted

0 votes
Accepted answer

so here is the script I created to solve this, is probably isn't the most elegant but our JIRA instance is an oddball. 


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.NumberFormat
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();

String att1 = "Field name1"; //call all your fields here

ArrayList list = new ArrayList();

list.add(att1); //add all fields to a list

Double passCount = 0;
int maxAttCount = 0;

if (list.isEmpty()) {
maxAttCount = 0;
else {
maxAttCount = list.size();
for (int i=0; i < maxAttCount; i++) {

String customField = list.get(i).toString();
if (customField != null){
CustomField cf = cfm.getCustomFieldObjectByName(customField);
Map cfVal = issue.getCustomFieldValue(cf) as Map;
if (cfVal){
String firstValue = cfVal.get(null);
if (firstValue.toString().equals("Pass")) { //this is the field attribute that will be calculated
passCount = passCount + 1;
else if (firstValue.toString().equals("Fail")) {

else if (firstValue.toString().equals("FYI")) {

else if (firstValue.toString().equals("NA")) {


int finalCount = passCount/15*100;
return finalCount + "%";
else if (firstValue.toString().equals("FYI")) {

else if (firstValue.toString().equals("NA")) {


int finalCount = passCount/15*100; //only 15 of the fields actually contain a fail attribute
return finalCount + "%" 

Hi Joe- you're likely going to need a scripting app to help perform mathematical operations to aggregate statistical information about a project, particularly when you're running metrics on options within a multi-option custom field.

Here's a quick example of a SIL script that you can run whenever an issue is created or edited in your project via SIL Listeners or on a set schedule with SIL Scheduler. This is made possible with Power Scripts for Jira.

string jql="project=PROJ"; //update with your project key 
string [] allProjectIssues=selectIssues(jql);

number totalProjectIssues=0;
number totalPasses=0;

for(string issue in allProjectIssues) {
totalProjectIssues += 1;
if(%issue%.customfield_12345=="Pass") {
totalPasses += 1;

number percentPass = (totalPasses / totalProjectIssues) * 100;
customfield_23456 = percentPass; // assumes you want to store this value in a number custom field

Hope this helps!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,221 views 5 10
Read article

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