> ## Documentation Index
> Fetch the complete documentation index at: https://valuemap.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Formula Builder

When adding or editing a benefit or cost, you can switch from a simple numeric value to the **Formula** mode. The Formula Builder lets you define dynamic calculated values using variables, operators, and built-in functions. This is useful when a value depends on multiple inputs or business logic.

#### Variables

Variables let you define named inputs that feed into your formula. Click **+ Add variable** to create one, give it a name (e.g., `headcount`, `salary`), and assign a value. Variables can then be referenced by name directly in the formula expression.

#### Operators

| Category        | Operators                      | Description                                                                |
| --------------- | ------------------------------ | -------------------------------------------------------------------------- |
| **Arithmetic**  | `+ − × ÷ () ^`                 | Standard math operations.                                                  |
| **Comparison**  | `< >`                          | Compare two values. Returns true or false - used inside conditional logic. |
| **Conditional** | `? :`                          | Ternary operator used to write if/else logic inline.                       |
| **Logical**     | `and or not is not true false` | Combine or negate conditions.                                              |

#### Functions

| Function    | Description                        |
| ----------- | ---------------------------------- |
| `abs(x)`    | Returns the absolute value of `x`. |
| `round(x)`  | Rounds `x` to the nearest integer. |
| `min(x, y)` | Returns the smaller of two values. |
| `max(x, y)` | Returns the larger of two values.  |
| `sqrt(x)`   | Returns the square root of `x`.    |

#### Templates

The Formula Builder includes four pre-built templates to get you started quickly. Click any template to insert it into the formula field, then modify the variables as needed.

| Template            | Syntax                                               | Use case                                                         |
| ------------------- | ---------------------------------------------------- | ---------------------------------------------------------------- |
| If / Else           | `condition ? trueValue : falseValue`                 | Return different values depending on whether a condition is met. |
| If / Else if / Else | `condition1 ? value1 : condition2 ? value2 : value3` | Chain multiple conditions.                                       |
| Capped value        | `min(value, cap)`                                    | Ensure a value does not exceed a maximum ceiling.                |
| % of threshold      | `value > threshold ? value * rate : 0`               | Apply a rate only when a value exceeds a threshold.              |

As you build the formula, the **Calculated value** field at the bottom of the builder updates in real time to show the current result.

<Note>
  Formula mode applies to both Benefits and Costs. Switch between Simple and Formula modes at any time using the tab toggle above the value input field.
</Note>
