Breadcrumbs

Remaining budget - expenses tracked in subtasks

📚

Return the remaining budget after deducting the expenses of the sub-tasks to the budget of the task. The expenses and budget are represented in different Number custom fields.

Configuration

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

Expression

%{{issue.cfnnnnn} = null ? null : {issue.cfnnnnn} - sum(append(fieldValue(
{issue.cfppppp}, subtasks()), [0]))} 

Please, replace nnnnn with the ID of the Number custom field for the budget and ppppp with the ID for the Number custom field for the expenses in the above expression.

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?

This expression calculates the remaining budget for a work item by subtracting the total expenses recorded in its sub-tasks from the budget set for the main task. Both the budget and expenses are stored in separate custom Number fields.

2. Step-by-step breakdown

Let’s break it down:

  • {issue.cfnnnnn} = null ? null : ...: This checks if the budget field is empty (null). If it is, the result is also null (no calculation is done). Replace nnnnn everywhere in the expression with the actual field ID for your budget field.

  • fieldValue({issue.cfppppp}, subtasks()): This retrieves the expense values from all sub-tasks of the main work item. Replace ppppp with the actual field ID for your expenses field.

  • append(..., [0]): This ensures that if there are no sub-tasks (and therefore no expenses), a zero is included so the sum function works correctly.

  • sum(...): This adds up all the expense values from the sub-tasks.

  • {issue.cfnnnnn} - sum(...): This subtracts the total expenses from the budget to get the remaining budget.

  • %{...}: This syntax guarantees that the elements within are run as functions.

3. Examples

Suppose:

  • The main work item has a budget of 1,000 (in the custom field with ID 12345).

  • It has three sub-tasks, each with expenses recorded as 100, 200, and 50 (in the custom field with ID 67890).

The expression would:

  • Retrieve the budget: 1,000

  • Retrieve the expenses from sub-tasks: 100, 200, 50

  • Sum the expenses: 100 + 200 + 50 = 350

  • Subtract expenses from budget: 1,000 - 350 = 650

So, the remaining budget shown would be 650.

4. Real-life use cases

  • Project managers want to track how much budget is left for a task after accounting for all expenses logged in its sub-tasks.

  • Finance teams need to ensure that the total expenses of all sub-tasks do not exceed the allocated budget for the main work item.