Calculated field from two other fields' values
Asked by Jure Jerebic:

Hi everyone,

We have a requirement to take two fields' values (Urgency and Impact), both of which have levels 1-4 that can be selected, and calculate the average of those two into a third field (Priority). This has to happen either when an issue (of a particular request type) is created or when the Impact field is updated. How can we configure this automation most effectively?

Thanks!


Answers:
author: Nikola Perisic
body: Welcome to the community [@Jure Jerebic](/t5/user/viewprofilepage/user-id/5314319)

First you need to identify the IDs' for both of the custom fields that have been created. You would need to create the automation rule when the issue gets created for the specific issue type (unless this applies to all of the issue types).

For the action you would need edit issue and to select the Priority field - make sure that this field is different from the already existing system field - my suggestion give it a different name.

Basic calculation: {{issue.customfield_10486}} + {{issue.customfield_10487}}

Since you need average, do the addition of two custom fields then depracte it with 2.

comments: author: Jure Jerebic
body: What would I set as the trigger? I need this to run whenever an issue of that request type is created or the Impact value is updated


author: Nikola Perisic
body: You can use only one of the triggers:

* Issue created - when the issue is created the automation rule will run
* Field value change - here you define when the field value change is happening for Impact then do the action


author: Jure Jerebic
body: That's what I thought as well, so I'll have to create two automations. Thanks!


author: Nikola Perisic
body: [@Jure Jerebic](/t5/user/viewprofilepage/user-id/5314319) Not quite. Only one when the issue is created then to do the calculation for the Impact field, which is done with Edit issue action.

So it would be like this:

* Trigger: Field value changes - here you will specify both Impact and Urgency
* Action: Edit issue - Impact field will be edited where in the input field you will be putting the calculation between the Urgency and Impact


author: Jure Jerebic
body: No, I meant two different automations for:  

1. issue is created -\> do the calculation and update the final calculated field  
2. issue is updated (Impact is edited - we won't change the Urgency) -\> do the calculation and update the final calculated field


author: Nikola Perisic
body: Ah, I didn't know you want to do the calculation twice. But, yes in that case, you would need two. Also, if you found my answer helpful, please mark it as accepted as there might be other people asking this question, so they can reference it easier.


author: Jure Jerebic
body: [@Nikola Perisic](/t5/user/viewprofilepage/user-id/5494176) I'll set it up next week and let you know, much appreciated for the time being!


author: Jure Jerebic
body: I can't seem to add the calculation into the Edit Issue action, I can only pick between the options that are available there; I also don't know what exact calculation I should use to get the average of two fields; note that this field that should be calculated is a single select field - or do they have to be text fields?

![Screenshot 2024-08-30 at 13.54.46.png](https://community.atlassian.com/t5/image/serverpage/image-id/344776iC901DD93789BC3F2/image-size/large?v=v2&px=999 "Screenshot 2024-08-30 at 13.54.46.png")


author: Nikola Perisic
body: To find the average of two numbers, you should sum them first then divide by 2. You need to replace the {{issue.customfield_xxxx}} with the IDs' of your custom fields that you are doing the calculation for. To find the IDs', navigate to Settings \> Issues \> Custom fields. Find your fields and click on Edit details.

![Screenshot 2024-08-30 at 14.41.55.png](https://community.atlassian.com/t5/image/serverpage/image-id/344783iBD5381478674CB91/image-size/large?v=v2&px=999 "Screenshot 2024-08-30 at 14.41.55.png")

In the address bar you will see ID showing. In my case it's 10052, yours will be different.


author: Jure Jerebic
body: Would this syntax be correct?   

{{#=}}({{issue.fields.Impact}} + {{issue.fields.Urgency}}) / 2{{/}}  

Also, I still cannot add that syntax into the automation to add it into that field, does it have to be a free text field?


author: Nikola Perisic
body: It's not correct, since you need to use the {{issue.customfield}}, please refer to the previous comment.


author: Jure Jerebic
body: So this then:  

{#=}}({{issue.customfield_11870}} + {{issue.customfield_11051}}) / 2{{/}}

What about the issue of not being able to add this to the destination field in the automation?![Screenshot 2024-08-30 at 14.59.51.png](https://community.atlassian.com/t5/image/serverpage/image-id/344785iF70110AE99CE0BE4/image-size/large?v=v2&px=999 "Screenshot 2024-08-30 at 14.59.51.png")


author: Nikola Perisic
body: {#=}} is not needed. Also the field has been specified which is Priority.Also for value changes you need to add the Urgency as well.


author: Jure Jerebic
body: I only want to change the value of Priority:  

1st source field: Impact (values 1-5)  
2nd source field: Urgency (values 1-5)  
Calculated end field: Priority (values 1-5)

This should happen in two scenarios:

1. a new ticket is created

2. value of Impact is edited on an existing ticket


author: Nikola Perisic
body: To better explain:

1.When the new ticket gets created, Priority gets calculated based on the formula from the screenshots

2. I see, it was not mentioned by the way that this is for the existing ticket. Nevertheless, Priority is based on the calculation of Impact and Urgency

What supposed to be a confusion here? Maybe I do not understand it as well.


author: Jure Jerebic
body: Correct, so it should use that formula. However, I can't paste the formula into the field in the worklow, see the screenshot above


author: Dexter de Vera
body: Hi [@Jure Jerebic](/t5/user/viewprofilepage/user-id/5314319) ,

Welcome to the Atlassian community,

You can follow this sample automation:

Trigger: Field value changed - impact

Condition:

If or Else Add condition option:

If block:

Add condition -

Issue field condition - Impact equals 1

Issue field condition - Urgency equals 1

Action: Edit field - Priority - low

Add else (If else)

follow the condition and action then change the value

So on and so forth until you align all the condition and value.

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

You can check this list of documentation to learn more about creating and configuring Jira cloud automation.

<https://support.atlassian.com/cloud-automation/docs/create-and-configure-jira-automation-rules/>

Hope it helps.

Thank you

comments: author: Nikola Perisic
body: Hi [@Dexter de Vera](/t5/user/viewprofilepage/user-id/4657717) , [@Jure Jerebic](/t5/user/viewprofilepage/user-id/5314319) is looking for calculating two fields,not just the automation set up.


author: Jure Jerebic
body: Nikola is correct, I don't want to set up a whole line of all the possible calculations through conditions


author: Dexter de Vera
body: [@Nikola Perisic](/t5/user/viewprofilepage/user-id/5494176) Alright. On my own understanding based on the description of this question, I think his looking for a condition based on the value selected in the dropdown list (Urgent and Impact) and then select the appropriate Priority. But yes, you can explain to him based on what you understand. Thanks!


author: Dexter de Vera
body: [@Nikola Perisic](/t5/user/viewprofilepage/user-id/5494176) Alright. you may follow the instructions of [@Nikola Perisic](/t5/user/viewprofilepage/user-id/5494176) answer.

Thank you!


Tags: cloud

jira-service-management

jira-service-management-cloud