﻿# Calculated fields

> [HTML Version](360013448740.html)

BRIX can automatically calculate field values on app pages. For instance, it can calculate the total price of an order including VAT or a customer discount. The system can also show or hide particular fields depending on conditions.

These options become available when you switch to the [Advanced Mode](360028941032.md) form editing. Go to the [Context](360028941112.md) tab and click on the property you want to set up. In the provided settings window check the **Set a formula for the field** box or **Show only when a condition is met**.

**(CF1.png)**

Let‘s take a look at how these settings work. 

## Set a formula for the field

````
начало внимание

````
This option is only available for **String**, **Number**, and **Money** field types.

````
конец внимание

````
If the **Set a formula** **for the field** option is enabled, the **Formula\*** field appears. You can add, subtract, calculate and divide the values with the following operators: **+**, **-**, **\***, **/**. Use parentheses **()** to define the order of operations.

You can add a variable of the same type as the calculated field to the formula. To do that, click **\{+\}** and select the variable from the list.

For example, to the formula for a **String** property, add **String** type variables. In case of a **Number** property, use **Number** type variables in the formula. If you add a variable of a different type, a validation error will occur.

The only exception is the **Money** type. In a formula for a **Money** type property, you can use the **Money\*Number** combination, meaning that you can multiply the value of the **Money** field by the value of the **Number** field.

Let‘s say a company sells and delivers heating installations. When an order is made, the sales rep enters all the details into the system: the customer‘s name, the goods purchased, the delivery date, etc. They might also want to enter a discount. Since the discount may vary depending, for instance, on the order‘s size, it is convenient to use a formula to calculate the total amount to be paid. 

**(CF2.png)**

To set up this behavior, open the order form for editing. Go to the **Context** tab and create a new **Total with discount** property. Select the **Money** type since we are calculating the final amount to be paid. 

Check the **Set a formula for the field** box. The required **Formula** field will appear. Click on the plus symbol **\{+\}** in the right corner of the line. A list of app fields with pop up. Select the **Total amount **variable of the** Money **type** **(this is the right table column, where the total price of the order is calculated before the discount is applied) and the **Discount **variable of the **Number** type (this is the field where the sales rep enters the discount‘s amount when registering the order).

Your final formula shall look as follows:

**(CF4.PNG)**

Save the changes. Now, when filling in the order form, the sales rep will enter the purchased products, the number of items purchased, and the discount amount. The system will automatically calculate the total amount to be paid minus the discount.  

**(CF5.gif)**

## Show fields based on conditions

Sometimes you need to hide or show fields on the form depending on certain conditions. Let‘s say our company provides different delivery options, including pickup and courier delivery. When a sales rep registers a new order, he or she specifies the delivery method selected by the customer. If the customer has selected courier delivery, an additional address field will appear on the form. In the case of pickup, the field will stay hidden. 

**(CF6.gif)**

To set up this behavior, open the order form for editing. Go to the **Context** tab and create a new **Delivery address** property. Check the **Show only when a condition is met** box and then click on the **Add Conditions** link. 

**(formula-field-03.PNG)**

In the pop-up, you can now set up the show condition for the field. If the conditions are not met, the field will remain hidden. 

**(formula-field-02.PNG)**

- **Field**.** **Select a property from the app's context.

- **Operation**.** **Select the operator for checking this condition.

- **Field Value**. Select a property or enter a value that will make the condition true.

- **Logical Operator**. A logical operator used to evaluate multiple conditions. If the result is **True**, the field will be displayed in the form:

	- **OR**.** **The result is **True** if at least one condition is met.

	- **AND**.** **The result is **True** if both conditions are met.

	- **OR NOT**.** **The result is **True** if the first condition is met or the second condition is not met.

	- **AND NOT**.** **The result is **True** if  if the first condition is met and the second condition is not met.

Note that conditions are checked in the order they are listed.

## Field display when added on a form in interface designer

You can place a field with the **Show only when a condition is met** option enabled onto a form in the interface designer. It is placed inside the **Field** widget, which has its own visibility settings.

For more details on which option takes priority for field display in different cases, refer to the [BRIX TS SDK documentation](https://tssdk.brix365.com/en/2026.5/pages/how-to/make-dynamic-display-of-fields-and-widgets-with-complex-condition.html#4).