---
title: "Set Value and Expressions"
description: "Set a calculated Embedded Data field anywhere in the survey flow from an expression: scores, auto-coding, text joining and days since a date."
icon: "equals"
---

A **Set value** step writes a calculated [Embedded Data](/surveys/general-features/variables) 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](/surveys/general-features/flow-tab).

## 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](/images/surveys/general-features/set-value/one-step-operators.webp)

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](/images/surveys/general-features/set-value/expression.webp)

### 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](/images/surveys/general-features/set-value/date-one-step.webp)

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

## True/false

A calculated field can be **true/false**, for example `qualified` to mark respondents who passed a screener. Choose **True/false** as its type in the Embedded Data card, and pick its default value, **True**, **False** or none.

A true/false field is set in one step only. Its row offers **Assign** alone, and the value is picked from a list: **True**, **False**, or another true/false field, calculated or passed in. There is no typed value, no question and no **Expression** switch: expressions don't give true or false yet.

* A passed-in field is copied as true or false: `?is_pro=true` in the URL sets the calculated field to true.
* When the field it copies has no value, the step leaves the calculated field as it was, as an empty value does for every other type.

The value is stored as `true` or `false`. Use the field in a condition with **equals** **True** or **False**, filter responses by it, and find it in the response table and in exports as `true` or `false`.

Through the API, a true/false field is set with `operator: "assign"` and a static `true` or `false`, or a `variable` or `hiddenField` value naming another true/false field. Any other operator, value or an expression is refused when you save:

```json
{
  "id": "clact123456789012345678902",
  "objective": "calculate",
  "variableId": "<the field's storageKey>",
  "operator": "assign",
  "value": { "type": "static", "value": true }
}
```

## 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 sets a true/false field, which takes only True, False or another true/false field, in one step
* it nests deeper than 12 levels or has more than 200 parts

## Through the API

The [Management API](/api-v3-reference/introduction) and [MCP](/platform/mcp/overview) 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
{
  "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 four 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
* a Set value step that sets a calculated **true/false** field to True or False: the previous release accepts only text and numbers as a typed value

The previous release also doesn't know calculated **true/false** fields at all:

* Through the [Management API](/api-v3-reference/introduction), MCP or the Embedded Data library, it refuses to save a calculated true/false field, even one no step sets.
* A response value for such a field is stored as a JSON boolean, `true` or `false`, which it doesn't accept: it accepts only text and numbers, such as the text `"true"` a hidden field carries. It refuses to create or update a response that carries one, and its background jobs for such a response (webhooks, integrations, follow-up emails) fail. The survey doesn't resend a refused update, so a response whose final update reaches such a pod stays unfinished. A background job that fails on every retry isn't run again after the upgrade, so its webhook, integration or follow-up email is never sent.
* A condition it checks on the server, such as a quota, gets such a field wrong: it never matches **equals True**, and it reads a stored `false` as not set.

Only surveys saved with one of these, and their responses, are affected, and only while previous-release pods are still serving, but what fails in that window (a refused update, a background job out of retries) isn't made up afterwards. 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.
