Breadcrumbs

Sum of field values from subtasks

📚

Return the sum the values of a specific field from all subtasks.

Configuration

Create a Custom smart number field and use the General parsing mode.

Expression

%{sum(fieldValue({issue.cfnnnn}, subtasks()))}

Please, replace nnnnn in the above expression with the ID of the Number custom field of the subtasks you want to sum up.

Display as

Number

Formatting style

Default (unformatted)

Used parser functions

The links lead to the JWTC documentation because the parser functions are shared functionalities.

Details

1. What does the expression do?

The expression calculates the total (sum) of a specific Number field from all subtasks of a work item. In other words, it adds up the values of a chosen field from each subtask and returns the result.

2. Step-by-step breakdown

The expression is:

%{sum(fieldValue({issue.cfnnnn}, subtasks()))}

Let’s break it down:

  • %{ ... }: This syntax is used to interpret the elements within as an advanced expression.

  • sum(...): This function adds together all the values provided to it.

  • fieldValue({issue.cfnnnn}, subtasks()):

    • fieldValue(...) retrieves the value of a specific field from a set of work items.

    • {issue.cfnnnn}: Replace nnnnn with the actual ID of the custom number field you want to sum up. This tells the parser which field to look at in each subtask.

    • subtasks(): This function returns all the subtasks of the current work item.

So, the expression gets all subtasks, retrieves the value of the specified custom number field from each subtask, and then sums those values.

3. Examples

Suppose you have a parent work item with three subtasks. Each subtask has a custom Number field (let’s say its ID is 12345):

  • Subtask 1: Field value = 5

  • Subtask 2: Field value = 10

  • Subtask 3: Field value = 7

If you use the expression:

%{sum(fieldValue({issue.cf12345}, subtasks()))}

The result will be: 5 + 10 + 7 = 22

4. Real-life use cases

  • Cost Calculation: If each subtask has a cost field, you can display the total cost for all subtasks in the parent work item.

  • Story Points: If you use a custom field for story points in subtasks, this will sum up the story points for reporting at the parent level.