Calculate numerical value of multiple choice test field
Asked by David.Mason:

Hi,

I am trying to create a prioritisation score which is based off of 3 categories and then added together into a final score.

I have three multiple choice fields.

Each have a number of options like below

Business Drivers

1 - New Business

2 - Increase Revenue

3 - Enhance Efficency

Customer Drivers

1 - Build Relationship

2 - New Product

Escalation

5 - Escalated.

I would like to convert each option to it's numerical value, add each option together then add each field together to create a Total Priority value.

I've attemped this multiple times with for each's and table look up's but I can't wrap my head around it. Any help appreciated!


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

You describe trying Lookup Tables, and so I wonder if you are using an automation rule.

If so, context is important for automation rule questions. Please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected. Those will provide context for the community to offer ideas. Thanks!

Until we see those...

You note using "multiple choice fields". Do you mean you are using:

* single-selection option fields, or
* multiple-selection option fields? (e.g., New Business and Increase Revenue are both selected)

If you are using multiple-selection, [Lookup Tables](https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Create-lookup-table) cannot easily be used. The reasons have to do with iterators and scoping. Regardless of that...

You could use a [list iterator](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#Combined-function-examples), [conditional logic](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/), and a [math expression](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/) to do this. For example to get the score for your Business Drivers, that could be:

```
{{#=}}
  0{{#issue.Business Drivers}}
    {{#if(equals(value, "New Business"))}} + 1{{/}}
    {{#if(equals(value, "Increase Revenue"))}} + 3{{/}}
    {{#if(equals(value, "Enhance Efficiency"))}}+ 5{{/}}
  {{/}}
{{/}}
```

This expression works by iterating over the selected values in the field, comparing them to desired value to add a number, and summing them with a math expression, using a default of 0 at the front.

Before proceeding, **please confirm you have the correct smart values (or custom field ids) for the fields** . Smart values are name, spacing, and case-sensitive, and when an incorrect one is used is is replaced with null, failing silently. To find the correct smart values, please use this how-to article: <https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/>

Kind regards,  
Bill

comments: author: David.Mason
body: Hi Bill,

Thanks for the response. You are in fact correct. I used the below calculation for each field, created a variable for each field then added the variables together to give me the desired output.

Thanks for your help!

Best regards,

Dave

Business Drivers

{{#=}}0{{#issue.Priority - Business Drivers}}{{#if(equals(value, "0 - None"))}} + 0

{{/}}{{#if(equals(value, "1 - Enhance Efficiency"))}} + 1

{{/}}{{#if(equals(value, "2 - Product Improvement"))}}+ 2

{{/}}{{#if(equals(value, "3 - New Product"))}}+ 3

{{/}}{{#if(equals(value, "4 - Increase Revenue - Current Business"))}}+ 4

{{/}}{{#if(equals(value, "5 - Increase Revenue - New Business"))}}+ 5

{{/}}{{/}}{{/}}

Customer Impact

{{#=}}0{{#issue.Priority - Customer Impact}}{{#if(equals(value, "0 - None"))}} + 0

{{/}}{{#if(equals(value, "1 - Reputational"))}} + 1

{{/}}{{#if(equals(value, "2 - Competitive Advantage"))}}+ 2

{{/}}{{#if(equals(value, "3 - Blocker Project Launch"))}}+ 3

{{/}}{{#if(equals(value, "4 - Blocker Contractual"))}}+ 4

{{/}}{{#if(equals(value, "5 - Non-Compliance"))}}+ 5

{{/}}{{#if(equals(value, "6 - Loss of Revenue"))}}+ 6

{{/}}{{/}}{{/}}

Stakeholder Alignment

{{#=}}0{{#issue.Priority - Stakeholder Alignment}}{{#if(equals(value, "5 - Escalated"))}} + 5

{{/}}{{#if(equals(value, "10 - Relationship with Customer"))}} + 10

{{/}}{{/}}{{/}}


Tags: cloud

jira-cloud