Applications are often required to make calculations involving the values of specific attributes, constants and/or functions. For all these cases, GeneXus offers Formulas.
There are different possible ways to define formulas. Let’s focus on Global Formulas.
Transaction Structures contain a column called Formula.

When a calculation is defined in this column for an attribute, it means that the attribute is virtual. In other words, it will not be created physically as a field in a table because the attribute value will be obtained every time it is needed by doing the calculation.
Note: If you are working in the Source selector of a Transaction object, and you want to define a formula for an attribute, click on the attribute name and go to the Properties window. There you will see a property named Formula for which you have to enter the calculation.
You can also use the assistant integrated into the Transaction. Let’s see this with an example.
Suppose the pharmacy needs to know at all times how many registered products there are of each product type.
To provide this information, go to the Source selector (for example, after the last defined attribute), type three slashes (///) to start the communication with the assistant, and enter the following:
///For each product type, it is necessary to know the number of products of that type.

When you press Enter, the assistant suggests creating an attribute named ProductTypeProductCount, of numeric type, which has a formula associated with it: a Count formula.

The formula called Count calculates the pharmacy's request (there are many others).
The attribute referenced inside the parenthesis of the formula indicates the table to be navigated to do the calculation (in the definition above, GeneXus Next knows that it has to count in the Product table).
If there is no relation between the table that will be navigated (Product) and the context where the formula attribute is defined (ProductType), GeneXus Next will do the calculation considering all records in the navigated table. However, if a relation is detected (primary attributes with the same name) between the table that will be navigated (Product) and the context where the formula attribute is defined (ProductType), only the related records will be considered for the calculation. So, in this case, for each product type, only products of that type are counted.
Press the Tab key to confirm that you accept the proposal.

Now press F5. As you can see, no physical changes will be made to the database. GeneXus will only generate some programs. Run the ProductType Transaction to see, for each product type, how the product count is calculated every time it is queried.

In addition, you can add more products to verify, for each product type, how the product count is calculated every time it is queried.
Defining calculations in the application - Formulas