---
title: "Add calculated fields and conditional logic to a form"
description: "Calculate totals with Formula fields (sum, round, if and more) and show a field only when another answer matches, with Show only when rules."
url: https://help.pdfbetter.com/forms/form-formulas-and-conditional-logic/
collection: "Forms & fillable PDFs"
section: "Building fillable forms"
updated: 2026-10-18
publisher: "PDFBetter (AI Generated Inc.)"
---

# Add calculated fields and conditional logic to a form

> Add a **Formula** field and type an expression such as `qty * price` or `sum(items_*_amount)` under **Calculation**. To hide a field until it's relevant, open its **Visibility** section, turn on **Show only when…** and add rules.

## Calculated fields

1. **Name the inputs**: Formulas refer to fields by their **Database name** (in **Field options**). Short names like `qty`, `price` and `tax_rate` are easier to type.
2. **Add a Formula field**: In **Create form** mode, choose **Formula** from **Add fields** and place it where the result should appear. Formula fields are read-only.
3. **Write the formula**: Under **Calculation**, type the expression. **Suggestions** offer field names and functions as you type, and the panel says **Formula is valid.** when it can be calculated.
4. **Test it**: Choose **Preview** and fill the inputs. The result updates as you type.

| You can use | Example |
| --- | --- |
| `+` `-` `*` `/` `%` `^` and brackets | `(hours * rate) - discount` |
| `sum`, `avg`, `min`, `max`, `count` | `sum(line1_total, line2_total)` |
| Wildcards in those functions | `sum(items_*_amount)` adds every field named items_…_amount |
| `round`, `abs`, `floor`, `ceil` | `round(subtotal * 0.0825, 2)` |
| `if(condition, then, else)` with `==` `!=` `<` `<=` `>` `>=` `&&` `\|\|` | `if(total > 1000, total * 0.1, 0)` |
| `concat` to join text | `concat(first_name, " ", last_name)` |

Empty fields are skipped by `sum`, `avg`, `min`, `max` and `count`. Amount fields round to their currency (two decimals, or whole yen), and you can set **Decimals** yourself.

> **Common formula errors:** **Unknown field** means a name doesn't match any Database name. **A formula can't refer to its own field.** and **Circular reference** mean two formulas depend on each other. Renaming a field updates the formulas that use it.

## Conditional logic: show a field only when…

1. **Select the field to hide**: Click the field that should appear only sometimes, for example "Spouse's name".
2. **Turn on Show only when…**: In **Field options**, open **Visibility** and turn on **Show only when…**.
3. **Add rules**: Choose a **Field**, a **Condition** and a **Value**, for example Marital status **is** Married. Choose **Add rule** for more, and set **Match** to **all** or **any** of the rules.

Conditions available: **is**, **is not**, **contains**, **is greater than**, **is less than**, **is empty**, **is filled**, **is checked** and **is not checked**. Text comparisons ignore upper and lower case.

- Hidden fields never block submission, even if they're marked **Required**.
- Formulas and visibility rules run in the PDFBetter editor, on published forms and on signing pages.
- Other PDF readers (Acrobat, Preview) show every field and the last calculated value; they don't run PDFBetter's rules. Publish the form if the logic matters.

### Can a formula use a dropdown or checkbox?

Yes. A dropdown's value is the chosen option, and you can compare it in `if`, for example `if(plan == "Pro", 15, 0)`.

### Why does my total show 0?

The input fields are empty, or the formula refers to names that don't match. Check the Database names in **Field options**.

## Related articles

- [Form field types, required fields and validation](https://help.pdfbetter.com/forms/form-field-types-and-validation.md): Pick a field type that matches the answer (Email, Date, Number, Phone…) and its format is checked as people type. Tick Required in Field options to stop the form being submitted or signed while the field is empty.
- [Make a PDF fillable by adding form fields](https://help.pdfbetter.com/forms/make-pdf-fillable.md): Open the PDF, switch the top bar to Create form, pick a field type from Add fields and click or drag it onto the page. Set its options on the right, check it with Preview, then download with Keep fillable or publish it as a form.
- [Publish a form as a fill link and collect responses](https://help.pdfbetter.com/forms/publish-form-fill-link.md): Build the fields, then choose Done → Publish as form, set the title and options, and select Publish form. You get a link, a QR code and embed code. Respondents don't need an account, and every submission is stored as data and as its own filled PDF.

---
Source: https://help.pdfbetter.com/forms/form-formulas-and-conditional-logic/ · PDFBetter Help Center · Last checked against the product 2026-10-18. Questions: support@pdfbetter.com
