The **Calculated field** of JetForms supports ternary operators which allow for building complex conditional formulas. With the help of this feature, you can calculate the tax payable based on different levels of income and the tax rate in the threshold.

**How Does It Work?**

The **Calculated field **allows building complex conditional formulas thanks to **ternary operators**‘ support. **Ternary operators** (also called **conditional operators)** help us construct conditional logic between several parts of the calculated formula.

The basic steps to build a conditional formula are described in the main tutorial on **How to Use Conditional Formulas in the Calculated Field**. Let’s put this knowledge to praxis and move on to the main use case of this article – calculating tax rates.

**Describing the Case**

Listed below are the necessary conditions for calculating tax rates in our example. The tax depends on the taxable income.

- For income from
**0**to**$18,200**, the tax equals**zero**. - For income from
**$18,201**to**$45,000**, the tax equals**15 cents****for each dollar over****$18,200**. - For income from
**$45,001**to**$120,000**, the tax equals**$5,000**; additionally, the person should pay**30 cents for each dollar over $45,000**. - For income from
**$120,001**, the tax equals**$30,000**; additionally, the person should pay**40 cents for each dollar over $120,000**.

**Building the Formula for Calculating Tax Rates**

**Add the necessary fields**

Navigate to ** JetFormBuilder > Forms > Add New** and open the Gutenberg editor. We need two fields for our purpose – a

**Number field**where the user can input the taxable income and a

**Calculated field**. Let’s name the

**Number field**“taxable_income”.

**Prepare for building the formula**

As outlined in our main tutorial on **How to Use Conditional Formulas in the Calculated Field**, a ternary operator takes three operands – a condition, an expression that needs to be executed if the condition is true, and an expression that will be executed if the condition is false. The primary condition is always followed by a question mark “**?**”, while the expressions are separated with a colon “**:**”.

In this specific use case, we combine several ternary operators in one formula to set several separate conditions.

- The first condition can be articulated like this: “If the “taxable_income” field contains a value less than or equal to 18200, then the final value 0; if not, the condition returns 0”.
- The second condition: “If the “taxable_income” field contains a value greater than 18200 but less than or equal to 45000, then subtract 18200 from the value of the “taxable_income” field and multiply by 0.15; if not, the condition returns 0”.
- The third condition: “If the “taxable_income” field contains a value greater than 45000 but less than or equal to 120000, then subtract 45000 from the value of the “taxable_income” field and multiply by 0.3 plus add 5000; if not, the condition returns 0”.
- The fourth condition: “If the “taxable_income” field contains a value greater than 120000, then subtract 120000 from the value of the “taxable_income” field and multiply by 0.4 plus add 30000; if not, the condition returns 0”.

Finally, all these conditions need to be summed to return a positive result.

**Build the formula**

Firstly, let’s build each conditional part of the whole formula separately.

For the first condition, the conditional formula should be the following:

`( %FIELD::taxable_income% <= 18200 ? 0 : 0 )`

Second condition:

`( %FIELD::taxable_income% > 18200 && %FIELD::taxable_income% <= 45000 ? 0.15 * ( %FIELD::taxable_income% - 18200 ) : 0 )`

Third condition:

`( %FIELD::taxable_income% > 45000 && %FIELD::taxable_income% <= 120000 ? 5000 + 0.3 * ( %FIELD::taxable_income% - 45000 ) : 0 )`

Fourth and final condition:

`( %FIELD::taxable_income% > 120000 ? 30000 + 0.4 * ( %FIELD::taxable_income% - 120000 ) : 0 )`

The final result consists of all four conditional formulas summed:

`( %FIELD::taxable_income% <= 18200 ? 0 : 0 ) + ( %FIELD::taxable_income% > 18200 && %FIELD::taxable_income% <= 45000 ? 0.15 * ( %FIELD::taxable_income% - 18200 ) : 0 ) + ( %FIELD::taxable_income% > 45000 && %FIELD::taxable_income% <= 120000 ? 5000 + 0.3 * ( %FIELD::taxable_income% - 45000 ) : 0 ) + ( %FIELD::taxable_income% > 120000 ? 30000 + 0.4 * ( %FIELD::taxable_income% - 120000 ) : 0 )`

Thus, three of the four conditional rules return 0, and only one rule returns the needed value.

**Check the result**

After you finished designing the form, navigate to the page or template where you wish to locate it. Test your form by inputting different values.

Now, your form for calculating tax rates is ready. Play around with conditions and design formulas of any complexity.