Formula

Formula

A Formula column calculates each cell from other columns in the same row, so users don't work out totals or scores by hand. Use it for line totals, such as quantity multiplied by unit price, and for values that depend on a condition, such as a discount for one category. Users can't edit a Formula cell.

Set up the formula

The formula isn't set in the Add New Column dialog. You write it after you save the column. Add the columns the formula uses first, because a formula can only use columns that already exist in the table.

  1. On the Table tab, in the row of the Formula column, select in the Actions column.

  2. Select Manage. The Manage Formula dialog opens.

  3. In Formula, enter the calculation. See Write a formula.

  4. Select Validate. A tick shows that the app can read the formula.

  5. Set the other settings you need. See Formula settings.

  6. Select Save.

Until you set-up and save a formula, every cell in the column shows Formula error.

Formula column configuration dialogue

Write a formula

The examples on this page use a Budget items table with the columns:

  • Text: Item

  • Select list: Category, with options Hardware, Software, and Services

  • Number: Quantity

  • Decimal number: Unit price

  • Formula: Line total or Handling fee

A formula can use the values only from the the same row. It can calculate with Number and Decimal number columns, and with Select list columns whose options are numbers, such as 1, 2, and 3. Select list columns with text options can be used in conditions, with compare.

Refer to a column by its name in double quotes, exactly as it appears in the column list. For example, this formula multiplies 2 columns:

"Quantity" * "Unit price"

Calculate with numbers

Use these operators:

  • + adds

  • - subtracts

  • * multiplies

  • / divides

Check a Select list option

To check which option a Select list column cell holds, use compare. It has 2 parts, separated by a comma, and you always follow it with == 0:

compare("column name", 'option') == 0
  • column name: the Select list column, in double quotes.

  • option: the option to look for, in single quotes, spelled exactly as in the column's option list. [VERIFY: whether capitals matter, Q2]

  • == 0: turns the result into a condition. compare gives 0 when the cell holds the option, which is the opposite of what you might expect. Adding == 0 makes the condition true when the option matches, and false when it doesn't.

How it works:

  1. The app looks at the Select list column cell in the row.

  2. If the cell holds the option, compare gives 0, so == 0 is true.

  3. If the cell holds any other option, compare gives a number other than 0, so == 0 is false.

Example: find the service lines.
You want to treat service lines differently from everything else, for example to give them a discount. First you need a condition that's true only in Services rows.

compare("Category", 'Services') == 0

Here's what each part does:

  • compare("Category", 'Services') looks at the Category column cell in the row and compares it with the Services option. It gives 0 when they match.

  • == 0 turns that into a condition: true in every row whose Category column cell holds the Services option, and false in every other row.

On its own, a condition only gives 0 or 1. To show a value that depends on it, use it in if or iff, described below.

How conditions work

A condition is a question about the row, such as "Is the quantity more than 10?". The formula language has no separate true and false. A condition works out to a number instead:

  • 0 means false: the condition doesn't hold.

  • Any other number means true: the condition holds.

For example, "Quantity" > 10 returns 1 in a row with Quantity 12, and 0 in a row with Quantity 5.

You can compare numbers with these operators:

  • > is more than

  • < is less than

  • == is equal to.

On their own, conditions only give 0 or 1. To show a value that depends on a condition, use if or iff, described below.

Choose between 2 values with if

Use if when a row gets one value when a condition holds and another value when it doesn't. It has 3 parts, separated by commas:

if(condition, value if true, value if false)
  • condition: the question about the row, for example "Quantity" > 10.

  • value if true: what the cell shows when the condition holds. It can be a number or a calculation.

  • value if false: what the cell shows when the condition doesn't hold.

How it works:

  1. The app works out the condition for the row.

  2. If the result isn't 0, the condition is true, and the cell shows the value if true.

  3. If the result is 0, the condition is false, and the cell shows the value if false.

Example: services get a 10% discount, and everything else is charged in full.

Your budget table lists hardware, software, and services. Services get a 10% discount, and everything else is charged at full price. You want the Line total column to work this out for each row, so nobody has to do the discount by hand.

if( compare("Category", 'Services') == 0, "Quantity" * "Unit price" * 0.9, "Quantity" * "Unit price" )

Here's what each line does:

  • compare("Category", 'Services') == 0 is the condition. The app looks at the Category column cell in the row and checks whether it holds Services option.

  • "Quantity" * "Unit price" * 0.9 is the value if true. It's the row's price, multiplied by 0.9. Multiplying by 0.9 keeps 90% of the price, which is the same as taking 10% off. The cell shows this when the row's category is Services.

  • "Quantity" * "Unit price" is the value if false. It's the full price, with no discount. The cell shows this for every other row: Hardware, Software, or no category at all.

Choose between several values with iff

Use iff when a row can get one of several values, depending on which condition it meets. For example, each category gets a different fee. iff is a list of rules that the app reads from top to bottom:

iff(condition 1, result 1; condition 2, result 2; 1 == 1, default result)
  • condition 1, condition 2: the questions about the row, for example "Quantity" > 10. You can add as many rules as you need.

  • result 1, result 2: what the cell shows when the condition just before it holds. It can be a number or a calculation.

  • 1 == 1, default result: the last rule. 1 always equals 1, so this condition is always true. It catches every row that no rule above it matched.

Inside a rule, a comma separates the condition from its result. Between rules, a semicolon separates one rule from the next.

How it works:

  1. The app works out the first condition for the row.

  2. If it's true, the cell shows result 1, and the app stops reading.

  3. If it's false, the app moves to the next rule and does the same.

  4. If none of the conditions above it is true, the last rule gives the default result.

Example: a handling fee for each category.
Every line in your budget table has a handling fee that depends on its category: 10 for hardware, 20 for software, and 30 for services. You want a Formula column called Handling fee to show the right fee in each row, so nobody has to look it up by hand.

iff( compare("Category", 'Hardware') == 0, 10; compare("Category", 'Software') == 0, 20; compare("Category", 'Services') == 0, 30; 1 == 1, 0 )

Here's what each line does:

  • compare("Category", 'Hardware') == 0, 10; is the first rule. The app looks at the Category column cell in the row and checks whether it holds the Hardware option. If it does, the cell shows 10, and the app stops reading.

  • compare("Category", 'Software') == 0, 20; is the second rule. The app reads it only when the row isn't Hardware. If the cell holds the Software option, the cell shows 20.

  • compare("Category", 'Services') == 0, 30; is the third rule. If the cell holds the Services option, the cell shows 30.

  • 1 == 1, 0 is the default rule. The app reaches it only when the row matched none of the rules above. The cell shows 0.

Combine conditions with AND and OR

Sometimes one condition isn't enough: a row must meet 2 conditions at once, or at least one of several. Because every condition works out to a number, you combine conditions with arithmetic. Put each condition in round brackets, so the app works it out before it combines them.

Require all conditions (AND)

Multiply the conditions:

(condition 1) * (condition 2)

How it works:

  1. The app works out each condition: 1 when it's true, 0 when it's false. [VERIFY: a true comparison gives 1, Q1]

  2. It multiplies the results.

  3. Any number multiplied by 0 is 0. So the result is 1 only when every condition is true. If even one is false, the result is 0, which means false.

Example: hardware lines with more than 10 items.
You want a condition that's true only for hardware lines with more than 10 items, for example to discount bulk hardware orders.

(compare("Category", 'Hardware') == 0) * ("Quantity" > 10)

Here's what each part does:

  • (compare("Category", 'Hardware') == 0) checks whether the Category column cell holds the Hardware option: 1 if it does, 0 if it doesn't.

  • ("Quantity" > 10) checks whether the Quantity column cell holds more than 10: 1 if it does, 0 if it doesn't.

  • * multiplies the two. A hardware line with 12 items gives 1 multiplied by 1, which is 1: true. A hardware line with 5 items gives 1 multiplied by 0, which is 0: false. A software line with 12 items gives 0 multiplied by 1, which is 0: false.

Require at least one condition (OR)

Add the conditions, then check that the sum is above 0:

((condition 1) + (condition 2)) > 0

How it works:

  1. The app works out each condition: 1 when it's true, 0 when it's false.

  2. It adds the results.

  3. The sum is 0 only when every condition is false. If at least one is true, the sum is above 0, so > 0 is true.

The extra round brackets around the sum tell the app to add first, then compare the sum with 0.

Example: hardware or software lines.
You want a condition that's true for hardware lines and for software lines, but not for services.

((compare("Category", 'Hardware') == 0) + (compare("Category", 'Software') == 0)) > 0

Here's what each part does:

  • (compare("Category", 'Hardware') == 0) gives 1 when the Category column cell holds the Hardware option, and 0 otherwise.

  • (compare("Category", 'Software') == 0) gives 1 when it holds the Software option, and 0 otherwise.

  • + adds the two. A hardware line gives 1 plus 0, which is 1. A software line gives 0 plus 1, which is 1. A services line gives 0 plus 0, which is 0.

  • > 0 is true when the sum is above 0: true for hardware and software lines, false for services lines.

Use a combined condition in if or iff

A combined condition goes anywhere a single condition can go.

Example: discount bulk orders of hardware and software.
Hardware and software lines with more than 10 items get a 5% discount. Every other line is charged at full price.

if( (((compare("Category", 'Hardware') == 0) + (compare("Category", 'Software') == 0)) > 0) * ("Quantity" > 10), "Quantity" * "Unit price" * 0.95, "Quantity" * "Unit price" )

Here's what each line does:

  • The first line is the condition. It multiplies 2 parts, so both must be true. The first part is the OR from the example above: the Category column cell holds the Hardware or the Software option. The second part, ("Quantity" > 10), checks that the line has more than 10 items.

  • "Quantity" * "Unit price" * 0.95 is the value if true. Multiplying by 0.95 keeps 95% of the price, which is the same as taking 5% off.

  • "Quantity" * "Unit price" is the value if false: the full price, for every other line.

Formula settings

You set these in the Manage Formula dialog.

Setting

What it does

Setting

What it does

Formula

The calculation. See Write a formula.

Decimal Length

The number of decimal places in the result.

Numbers Aggregation

Adds a read-only row below the table with the sum, average, minimum, or maximum of the column, for example the total of all line totals.

Store value in the properties for the index search

When selected, the app stores the calculated values so that users can search work items by them with JQL. This might affect the performance of the table, so select it only for columns that users search.