Expressions let you create smart, responsive surveys that adapt to each respondent in real time. With expressions, you can personalize content, show or hide questions dynamically, perform calculations, and apply custom logic without writing complete scripts.
This guide walks you through practical examples to help you use expressions effectively in FC Surveys, starting with simple examples and moving into advanced use cases.
Personalizing Questions with Piped Text
Use expressions to repeat or reference answers from earlier questions. These "shortcuts" add a human touch and help respondents stay engaged.
Example:
- Q1: What is your name? (Question name:
name) - Q2: Thanks, {name}. On a scale of 1–5, how satisfied are you with our service?
Here, {name} dynamically inserts the respondent's answer from Q1 into the Q2 prompt.
Showing or Hiding Questions Based on Answers
Use the visibleIf property to conditionally display a question based on earlier inputs.
Example:
- Q1: What is your age? (Question name:
age) - Q2 (visible only if 18 or older): Have you voted in the last election?
"visibleIf": "{age} >= 18"
This logic ensures only adult respondents see the voting question.
Performing Real-Time Calculations
Use expressions to compute scores, totals, or other values across multiple answers.
Example:
- Q1–Q3: Rate the following on a scale from 1–5.
- Q4 (calculated value): Total score
"expression": "{q1} + {q2} + {q3}"
Use calculated values to segment users, control logic, or drive branching.
Prefilling Values with Default Expressions
Expressions can set default answers based on known data or earlier inputs.
Example:
- Q1: What is your age? (Question name:
userAge) - Q2: Confirm your age
"defaultValueExpression": "{userAge}"
This helps reduce friction for respondents and ensures consistency.
Validating Inputs with Expressions
Go beyond basic required fields by writing validation expressions.
Example:
- Q1: What is your age?
- Add a validator to enforce a minimum age:
"validators": [
{
"type": "expression",
"expression": "{age} >= 13",
"text": "You must be at least 13 to participate."
}
]
Expression Syntax Reference
Use the following table as a quick reference when writing expressions in FC Surveys:
Operators
| Type | Symbol(s) | Example |
|---|---|---|
| Equal | = or == | {age} == 18 |
| Not equal | != | {gender} != "male" |
| Greater than | > | {score} > 75 |
| Less than | < | {score} < 25 |
| Greater/Equal | >= | {age} >= 13 |
| Less/Equal | <= | {age} <= 65 |
| And | and or && | {age} >= 18 and {country} == "US" |
| Or | or or ` | |
| Not | ! | !{completed} |
Functions
| Function | Purpose | Example |
|---|---|---|
iif() | Conditional logic | iif({age} >= 18, "Adult", "Minor") |
age() | Age from date | age({birthdate}) |
today() | Current date | today() |
dateDiff() | Days/months/years between dates | dateDiff({start}, {end}, 'D') |
min() / max() | Min or max of values | min({q1}, {q2}) |
sum() | Sum of multiple values | sum({q1}, {q2}, {q3}) |
Write expressions in FC Surveys using the following supported syntax, operators, and built-in functions.
Value Access Patterns
Question values
{questionName}— Returns the value of the referenced question.
Indexed or contextual access
{qid[0]}— First item from a multi-select or ranking question.{qid.itemid}— Item from a multiple-textbox question.{row.columnid}— Matrix question cell in the current row.{prevRow.columnid}— Value from the previous matrix row.{nextRow.columnid}— Value from the next matrix row.{rowIndex}— Index of the current matrix row.{visibleRowIndex}— Index among visible matrix rows.{rowName}— Row identifier.{rowTitle}— Row label.{matrixid-total.columnid}— Cell in the matrix total row.{panel.qid}— Value from a question in the same dynamic panel.{prevPanel.qid}— Value from the previous panel.{nextPanel.qid}— Value from the next panel.{parentPanel.qid}— Value from the parent panel.{dpanelid[0].qid}— First instance of a question in a dynamic panel.{dpanelid[-1].qid}— Last instance of a question in a dynamic panel.
Comparison Operators
| Operator | Description |
|---|---|
= or == | Equal |
!= or <> | Not equal |
<, > | Less than / greater than |
<=, >= | Less than or equal / greater than or equal |
empty | Value is null or undefined |
notempty | Value is defined |
*= or contains | Value contains string or item |
notcontains | Value does not contain item |
anyof | Value is in a list |
noneof | Value is not in a list |
allof | Value contains all listed items |
Logical Operators
| Operator | Description |
|---|---|
! | Logical NOT |
&& or and | Logical AND |
or | Logical OR |
Arithmetic Operators
| Operator | Description |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus (remainder) |
^ | Power |
Built-in Functions
Conditional Logic
iif(condition, trueValue, falseValue)— Returns one of two values based on a condition.
Date and Time Functions
age(date)— Returns the number of years since the given date.currentDate()— Returns the current date and time.today(offset)— Returns today’s date, optionally adjusted by days.year(date)— Extracts the year from a date.month(date)— Extracts the month (1–12).day(date)— Extracts the day of the month (1–31).weekday(date)— Returns the weekday (0–6).dateDiff(date1, date2, unit)— Returns the difference between two dates.dateAdd(date, amount, unit)— Adds a number of units (days, months, etc.) to a date.
Aggregation Functions
sum(value1, value2, ...)— Returns the sum of values.min(...)— Returns the smallest value.max(...)— Returns the largest value.avg(...)— Returns the average of values.
Array and Panel Functions
sumInArray(questionName, columnName, filter)— Sum of column values in an array.minInArray(...),maxInArray(...),avgInArray(...)— Similar aggregation across arrays.countInArray(...)— Counts non-empty values in a column or panel.
Notes
- All question references are case-sensitive.
- Use double quotes around string literals.
- Use parentheses to group operations for clarity.
- When referencing array or matrix data, ensure the structure matches your survey design.