# Scores and calculations

> Keep a score or a total as people answer — grade a quiz, qualify a lead, price an order — then send people to an ending by it, show it to them, and read it in your responses.

A **variable** is a number the form keeps while someone answers it: a quiz score, a lead's grade, an order total. Each question can change it with **calculations** — "add 1 to score when the answer is Canberra" — logic can send people to a different ending depending on it, you can show it on any screen, and every response keeps its final value.

Scores and calculations are on every plan.

## Build a scored quiz, step by step

This builds a three-question quiz that gives a point per right answer, adds the respondent's own rating of the quiz, and finishes on a different ending for a high score. Every step names the control exactly as it appears in the builder.

### 1. Write the questions

In a new form, add three questions:

1. **Multiple choice** — "What's the capital of Australia?" with the choices Sydney, Melbourne and Canberra.
2. **Number** — "How many planets are in the solar system?"
3. **Rating** — "How would you rate this quiz?", with 5 steps.

### 2. Name the number you're keeping

Select question 1, and in the settings pane open **Scores and calculations**.

1. In **Name what you're counting**, leave `score` (or type another name, like `points`).
2. Select **Create variable**.

The name is for the number itself, not for an answer: if you type one of the question's answers, like "Canberra", the builder says so and asks for a name like `score` instead.

### 3. Give each answer its points

Creating the variable lists every answer of question 1 at **0**:

- **Sydney** — Add `0` to score
- **Melbourne** — Add `0` to score
- **Canberra** — Add `0` to score

Nothing is marked right for you. Change **Canberra** to `1` and leave the others at `0`. (Wrong answers can take points away too: type a negative number, like `-1`.)

On a multiple choice, dropdown or yes/no question that already has some calculations, **Score the answers** adds a row for each answer that doesn't have one yet.

### 4. Score a typed answer

Select question 2.

1. Under **Scores and calculations**, select **Add calculation**. It reads "Adds 1 to score, every time someone moves past this question."
2. Change **Every time** to **Only when…**. The condition starts on **is** with an empty box.
3. Type `8` in the box. The card now reads "Adds 1 to score when the answer is 8."

> [!WARNING]
> Check the sentence under each calculation. "When this question is answered, whatever the answer" means any answer scores.

### 5. Add someone's own number

Select question 3.

1. Select **Add calculation**.
2. Tick **Use their answer as the amount**. The card reads "Adds their answer to score, every time someone moves past this question."

This is how a form adds up ratings, or multiplies a quantity by a price with **Multiply by**.

### 6. Show the score

Until something shows or uses a variable, the panel reminds you: "Respondents won't see score yet."

1. In the question list, under **Endings**, select the ending (or **Add ending**).
2. Write its title, and put the cursor where the score should go.
3. Select **Insert answer → Variable: score**. The title becomes `You scored {{var:score}} out of 7.`

### 7. Send high scores to their own ending

1. Select **Add ending** and title it `Top marks: {{var:score}} out of 7!`
2. Select question 3, open **Logic** in the settings pane and select **Add rule**.
3. Set **If** to **Variable: score**, the comparison to **is at least**, and the value to `6`.
4. Set **Then go to** to the _Top marks_ ending.

Rules on question 3 see the score _after_ its own calculations, so the rating already counts.

### 8. Publish and try it

Select **Publish**, open the form from **Share**, and take it:

- Canberra, 8 and a rating of 5 scores 7, and lands on **Top marks: 7 out of 7!**
- Sydney, 9 and a rating of 2 scores 2, and lands on **You scored 2 out of 7.**
- Answer Canberra, go back with **↑**, change it to Sydney, and finish: the score drops by one. Going back never leaves a stale score.

Then open **Responses**: the **score** column is right after the date.

## More examples

### Qualify a lead

Variable `lead`. On "Company size", score each answer: 1–10 people `0`, 11–50 `5`, 51–200 `10`, over 200 `20`. On "When do you want to start?", score _This month_ `10`. Then a rule on the last question — **Variable: lead** **is at least** `20` — goes to an ending that offers to book a call, while everyone else gets the standard thank-you. Email notifications list `lead` first, so the team sees the grade at a glance.

### Price an order

Variable `total`. On "Which plan?", select **Score the answers** and put each plan's monthly price on its answer: Starter `19`, Team `49` (`total` starts at 0, so adding the price sets it). On "How many seats?" (a number), **Add calculation**, choose **Multiply by** and tick **Use their answer as the amount**. On "Add priority support?" (yes/no), put `99` on **Yes**. The ending says `Your total is ${{var:total}} a month.`

## Managing variables

**Settings → Variables** lists the form's variables.

- **Add variable** creates another one — a form can keep several, like `score` and `attempts`.
- **Starts at** sets where one begins; it's 0 unless you say otherwise.
- The remove button deletes one, together with the calculations that change it, the conditions that check it and anywhere it's shown. Responses keep the values they already saved.

## How calculations run

- They run in order when someone moves past the question, and before the question's own [logic](https://formhelix.com/docs/logic).
- Only the questions someone actually passes count. If logic skips a question, its calculations never run.
- The score is worked out again from the answers each time, so going back and changing an answer changes the score with it.
- **Divide by** zero is skipped rather than breaking the total, and a calculation that uses an answer that wasn't given is skipped too.
- Values are kept to ten decimal places and shown with up to two.

## Branching on a score

Every [logic](https://formhelix.com/docs/logic) rule and [follow-up](https://formhelix.com/docs/follow-ups) trigger can check a variable, listed as **Variable: score**. Compare it with **is**, **is not**, **is less than**, **is greater than**, **is at least** or **is at most**.

## Showing a score

Use **Insert answer → Variable: score** in any title, description or ending. It shows the value as it stands on that screen: everything answered before it has counted, so a running total works mid-form too. See [answer recall](https://formhelix.com/docs/answer-recall).

## In your responses

- Each variable gets its own column in the responses table, ahead of the answers, and a line at the top of each response's details.
- The CSV export has a column per variable, and [Google Sheets](https://formhelix.com/docs/google-sheets) adds one at the end of the spreadsheet.
- [Webhooks](https://formhelix.com/docs/webhooks) include them as `variables`, by name.
- Email notifications list them first.
- [Insights](https://formhelix.com/docs/insights) shows each variable's average, lowest and highest value over completed responses on Premium.

## Things to know

- A calculation can't use the answer of a number question marked as personal data: a score worked out from it would give the answer away.
- Duplicating a question doesn't copy its calculations, the same as its logic: the copy's answers are new ones.
- Changing a question's type resets conditions that checked it, and drops **Use their answer as the amount** if the new type doesn't answer with a number.
