Variable logic

Introduction

Variable logic evaluates conditions and saves values to predefined variables in your survey. When a respondent reaches a variable logic element, the condition is evaluated and, if true, the specified value is saved to the database. Variable logic elements are not visible to respondents.

Variable Logic Element

Writing variable logic

Variable logic is composed of three pieces

  1. Statements
  2. Conditions
  3. Set-value input
Variable Logic Element Anatomy

Logic statements and conditions work the same way as in skip logic — see the Skip logic article for a full walkthrough.

To set up a variable logic statement:

  1. Select an existing variable or create a new one to save values to. The selected variable appears in the statement header. Note that unique ID and URL variables are not available in variable logic. See the Variable manager. article for more on variable types.
  2. Define the condition using the dropdowns.
  3. At the end of the statement, enter the value to save when the condition evaluates to true.

Example

To segment respondents into "State side" or "Foreign" based on a Country question:

  • Statement 1: If Country = United States, set location to "State side."
  • Statement 2: If Country = Canada, Mexico, or Brazil, set location to "Foreign."
Variable Logic Example (stateside)

Advanced logic and scripting

Use {{ }} notation in the value input to write JavaScript for more advanced operations. For example, to calculate total household income from two numeric questions:

{{ getValue(“income1”) + getValue(income2) }}

This sums both responses and saves the result to the selected variable when the condition evaluates to true. Use the Insert variable button below the value input to quickly add variables with the correct getValue() syntax.

Example of advanced logic using scripting in the set-value input box