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

# Set Value and Expressions

> Set a calculated Embedded Data field anywhere in the survey flow from an expression: scores, auto-coding, text joining and days since a date.

A **Set value** step writes a calculated [Embedded Data](https://formbricks.com/docs/surveys/general-features/variables.md) field as the respondent moves through the survey. Its value comes from an expression, for example `round(@q1 + @q2 * 2)` for a score, `concat("segment-", @plan)` for auto-coding, or `daysBetween(@signup_date, now())` for days since a date.

You add and edit Set value steps on the [Flow tab](https://formbricks.com/docs/surveys/general-features/flow-tab.md).

## Adding a step

Under a block on the Flow tab, open **Add logic** and choose **Set value**. The new step always runs after the block is submitted, and reads **Always** on the outline.

A new step starts with **Expression** off, on **Assign**: choose the calculated field to set and the value it gets, a typed value, an answer or another field. Switch on **Expression** to work the value out with an expression instead. To set the value only for some respondents, use **Add a condition** on the step: it then runs only when the condition matches. Removing the condition makes it always run again.

With **Expression** off, a step reads field, operator and value, such as *score + 1*. For a number field, the operator list shows each operator with its symbol: **Add**, **Subtract**, **Multiply**, **Divide** and **Assign**. For a text field it offers **Assign** and **Append**, which adds the value to the end of the field's text; the outline reads it as *append "-vip" to segment*.

![A Set value step with Expression off: score, its operator list open with Add, Subtract, Multiply, Divide and Assign, and the value 1](https://mintcdn.com/formbricks/ujB3V7j_PCAkJ4_7/images/surveys/general-features/set-value/one-step-operators.webp?fit=max\&auto=format\&n=ujB3V7j_PCAkJ4_7\&q=85\&s=6a697ad17ca79c51cb9fa0939cbcd1b1)

To turn a one-step calculation into an expression, switch on **Expression** in its row. Switching it off turns an expression back into one step when it is one, such as *ifEmpty(@score, 0) + 1*; any other expression is cleared after you confirm. Changing an existing action to **Set value** starts it on **Assign** with **Expression** off, like a new step.

## Writing an expression

* **Numbers and text.** Type numbers as they are (`2`, `1.5`) and put text in quotes (`"gold"`). A date in quotes, such as `"2026-03-01"`, counts as a date where a date is expected.
* **Answers and fields.** Type `@` or use the **@** button to insert an answer or a field. Questions are named by their question code, Embedded Data fields by their name, and auto-captured fields such as `language` by theirs. A name with spaces is written in braces: `@{Plan tier}`.
* **Operators.** `+`, `-`, `*` and `/` work as in a calculator, with `*` and `/` first. Use brackets to change the order.
* **Functions.** Click a function chip to insert it, or type its name.

Below the expression, the box shows what a save would refuse, or the **sample result**: what the step computes for a made-up response with a typical answer to every question.

![A Set value step that always runs: fee\_score is set to round(ifEmpty(@fee\_clarity, 0) \* 20), with the function chips below the expression and the sample result If @fee\_clarity is 4, the result is 80](https://mintcdn.com/formbricks/ujB3V7j_PCAkJ4_7/images/surveys/general-features/set-value/expression.webp?fit=max\&auto=format\&n=ujB3V7j_PCAkJ4_7\&q=85\&s=0d91ceb8b68c96fc4eefeb01de134b67)

### What an answer is in an expression

| Question | In an expression |
| - | - |
| Rating, Net Promoter Score, CSAT, CES, a number open question | A number |
| Other open questions | Text |
| Date | A date |
| Single select | Its answer code, as text, in every language |

Other question types can't be used in an expression. An Embedded Data field has the type you gave it.

## Functions

| Function | Takes | Gives |
| - | - | - |
| `a + b`, `a * b` | 2 to 50 numbers | A number |
| `a - b`, `a / b` | 2 numbers | A number. Dividing by zero gives empty |
| `round(x)`, `round(x, 2)` | A number, and how many decimals (0 to 10) | The number rounded, halves away from zero |
| `min(a, b, …)`, `max(a, b, …)` | 2 to 50 numbers | The smallest or largest |
| `abs(x)` | A number | The number without its sign |
| `ifEmpty(x, fallback)` | A value and a fallback of the same type | `x`, or the fallback when `x` is empty |
| `concat(a, b, …)` | 2 to 50 values | Text: numbers and dates are written out as text |
| `now()` | Nothing | The date and time on the respondent's device, in UTC |
| `daysBetween(a, b)` | 2 dates | The calendar days from `a` to `b`, counted in UTC; negative when `b` is earlier |

## Empty values

* **Empty in, empty out.** When a question wasn't answered or a field isn't set, an expression that uses it is empty. Use `ifEmpty` to set a default: `ifEmpty(@q1, 0) + 1`.
* **Dividing by zero** gives empty.
* **A value that isn't a number** counts as empty where a number is needed.
* **Setting a field to empty clears it**, so the response doesn't keep an old value.

One-step calculations keep their old behaviour: there, an empty field counts as `0`.

## Dates

A calculated field can be a **date**. Set it with `now()` to record when the respondent reached a step, and use it in `daysBetween()` to count days, for example the days since a date passed in a URL parameter. Dates are stored as ISO 8601 timestamps in UTC, and they appear in exports like every other field.

With the **Expression** switch off, a date field is set to a date picked from the calendar, a date question's answer, or another date field. Anything more, such as `now()` or a date worked out with a function, needs the expression box. The calendar next to the expression box writes a picked date in quotes, such as `"2026-11-05"`, into the expression.

![A Set value step with Expression off that sets the date field fee\_review\_requested\_on to a picked date, Nov 13, 2026](https://mintcdn.com/formbricks/ujB3V7j_PCAkJ4_7/images/surveys/general-features/set-value/date-one-step.webp?fit=max\&auto=format\&n=ujB3V7j_PCAkJ4_7\&q=85\&s=10151206251688d10e8ebc4c81a9b7be)

`daysBetween()` counts calendar days in UTC, not 24-hour periods: from 23:59 to 00:01 the next day is one day.

## Checks when you save

An expression is checked when you save or publish the survey. It is refused, with the exact place marked, when:

* it uses text where a number is needed, such as an open text answer in `+`
* a function gets the wrong number of values, or a function doesn't exist
* it names a question or field the survey doesn't have
* its result doesn't fit the field: a number field takes a number, a text field text, a date field a date
* it nests deeper than 12 levels or has more than 200 parts

## Through the API

The [Management API](https://formbricks.com/docs/api-v3-reference/introduction.md) and [MCP](https://formbricks.com/docs/platform/mcp/overview.md) store the same expression as a tree, which is what the survey runs. A Set value step is a `calculate` action with `operator: "assign"` and an `expression` value:

```json theme={null}
{
  "id": "clact123456789012345678901",
  "objective": "calculate",
  "variableId": "<the field's storageKey>",
  "operator": "assign",
  "value": {
    "type": "expression",
    "value": {
      "type": "call",
      "fn": "round",
      "args": [
        {
          "type": "call",
          "fn": "add",
          "args": [
            { "type": "element", "value": "q1" },
            {
              "type": "call",
              "fn": "multiply",
              "args": [
                { "type": "element", "value": "q2" },
                { "type": "static", "value": 2 }
              ]
            }
          ]
        }
      ]
    }
  }
}
```

A step that always runs is a rule whose `conditions` is an empty `and` group. The survey evaluates expressions without `eval`, so they work on websites with a strict Content Security Policy.

## While upgrading a self-hosted instance

During a rolling upgrade to 6.2, the pods still on the previous release don't know three things a survey saved in that window may hold, and reject the survey wherever they validate it until the upgrade ends:

* a Set value step with an expression (the `expression` value)
* a **Mark response as Low quality** action
* a condition on a calculated **date** field, even one set only by its default value: the previous release looks the field up in the older `variables` list, which doesn't list date fields

Only surveys saved with one of these during the upgrade are affected, and only for its few minutes. Everything else 6.2 adds, such as show-if, Hidden options, copied options and rules before the first question, is ignored by the previous release and shown as before.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.