Formula Fields
Liferay DXP 2023.Q4+/Portal GA102+
Formula fields provide read-only values calculated using numeric fields in the object definition. Unlike other fields, formula values are calculated at runtime and are not persisted in the database. Common use cases include calculating an employee’s available PTO hours by subtracting pending requests or determining an agent’s commission based on an order’s total.
During field creation, you can set the output type as an integer or decimal. After creating the field, you must edit the field to define the formula used to calculate its value. Available functions include add (+), subtract (-), multiply (*), and divide (/). You can use these functions with any integer, long integer, decimal, and precision decimal fields in the object.
Because formula field values are not stored in the database, you can’t filter or sort entries by these fields.

For example, consider a scenario with two numeric fields, totalRevenue (precision decimal) and totalExpenses (precision decimal). You can add a formula field with this expression to calculate your net profit:
totalRevenue - totalExpenses

Additionally, you could add a formula field with this expression to calculate the profit margin:
(totalRevenue - totalExpenses) / totalRevenue * 100

Formula field values are calculated dynamically. Because these values are not stored in the database, they are generated only when an entry is retrieved for viewing or processing.
