aytm Logic is the bracketed syntax you type into question, answer, and sub-question fields in the survey editor to control survey flow, show or hide content, pipe responses, and run calculations. This page is a quick reference for every operator, command, and reserved variable. For a guided introduction, see aytm Logic Overview. Inside the editor, the Logic Guide in the left sidebar has interactive examples you can copy, and aytm Logic autocomplete suggests commands and references as soon as you type [.
Click here to download the aytm Logic Reference Guide.
In This Article
- Syntax Basics
- References
- Reference Modifiers
- Range Shortcuts
- Operators and Functions
- Variables and Arrays
- Display and Flow Commands
- Terminate and Quota
- Reserved Variables
- Examples
- Rule Priority
Syntax Basics
| Syntax | Description |
|---|---|
| [...] | aytm Logic must always be surrounded by square brackets. |
| [[Anything]] | Double brackets show a regular phrase in square brackets to the respondent. Typing [[optional]] displays [optional]. |
| [Q1I] = [q1i] | Commands and references are case-insensitive. Text compared with = ignores case too, but like is case-sensitive. |
| [show if Q2][hide if Q1A4] | You can place several commands in one field. Each is resolved on its own, and show/hide results combine with AND—if any hide condition applies, the field is hidden. |
| "one" / 'one' | Text value. Use double or single quotes; the text can contain any symbols as long as it's in quotes. |
| 1 / 0.5 / .5 | Numeric value. Decimals are supported. |
| (...) | Operations in parentheses are processed before others, e.g., [Q1i if (Q1A1 or Q2A1) and not (Q3A1 or Q4A1)]. |
| if | Adds a condition to almost any command, e.g., [Q10A1 if Q5A1] or [QuizScore + 1 if Q3A2]. |
References
A reference is the address of a field in your survey. How a reference behaves depends on where you use it:
-
On its own (e.g.,
[Q10A1]), it pipes in the field's text as written in the editor—here, the text of answer option A1, whether or not the respondent chose it. To pipe what the respondent chose, addR:[Q10R](see Reference Modifiers). -
In a condition, pointing to a question or sub-question (e.g.,
[show if Q5]), it is true if the respondent saw that question. -
In a condition, pointing to an answer (e.g.,
[show if Q5A1]), it is true if the respondent selected that answer.
| Syntax | Description |
|---|---|
| Q | Question, e.g., Q1
|
| PQ | Prequalification question, e.g., PQ1, PQ1A1
|
| SQ | Sub-question, e.g., Q1SQ1
|
| E | Entity (Competitive Topography and Quadrant questions), e.g., Q1E1
|
| A | Answer, e.g., Q1A1, Q1SQ1A1, Q1E1SQ1A1
|
| Q1A / Q1SQ / Q1E | All answers, sub-questions, or entities of a question (no number). Used by [Show first/last...] and [Sort...]. |
| @ | Field alias, e.g., @promoter. Starts with @ followed by letters (A–Z, a–z), digits (0–9), or underscores. Refers to the field where it's typed and keeps working when questions move. Aliases must be unique within a survey. |
| # | Hashtag, e.g., #premium. Tags answer options so options with the same tag can be grouped in results. Must start with a letter, followed by letters, digits, or underscores. See Hashtag Logic. |
⚠️ Note: To pipe answer text from a question with sub-questions, include the sub-question in the reference—
[Q1SQ1A5], not[Q1A5]. The respondent must have seen the element first; otherwise "logic error" is piped instead.
References by Question Type
Every question can be referenced as a whole (Q1 or PQ1). The table shows the deeper levels each question type supports.
| Question type | What you can reference | Example |
|---|---|---|
| Single choice prequal, Multiple positive choices prequal, Multiple negative choices prequal | Answer | PQ1A1 |
| Radio buttons, Checkboxes, Combobox, Cascade | Answer | Q1A1 |
| Reorder (ranking), Side-by-Side, MaxDiff | Item | Q1A1 |
| Forms | Field | Q1A1 |
| Video Response | Talking point | Q1A1 |
| Rapid Association, Impression Dial, Conversation AI | Answer-level item | Q1A1 |
| Ecommerce, Shelf Test, Menu Test | Product or menu item | Q1A1 |
| Sliders, Progressive Matrix | Sub-question; answer within a sub-question | Q1SQ1, Q1SQ1A1 |
| Smiley rating, Star rating | Sub-question; smiley or star within a sub-question | Q1SQ1, Q1SQ1A1 |
| Distribute | Item | Q1SQ1 |
| Polarity Scale | Scale; left end (A1) or right end (A2) | Q1SQ1, Q1SQ1A1, Q1SQ1A2 |
| Conjoint | Attribute; level within an attribute | Q1SQ1, Q1SQ1A1 |
| Quadrant Analysis, Competitive Topography | Entity; attribute of an entity; star or slider value | Q1E1, Q1E1SQ1, Q1E1SQ1A1 |
Heatmap references depend on the question's pin settings. With aytm Logic autocomplete turned on, the editor suggests valid references as you type.
When Questions Move or Are Deleted
References follow the field they point to, not its position. If you add a question in front of Q1, [Show if Q1A1] becomes [Show if Q2A1] automatically. The same applies to sub-questions, answers, and entities.
If you delete a referenced field, or change it so the reference can't follow it, the reference keeps its old number and gets a ? in front of it—for example, [Show if ?Q1A1]. Click the highlighted reference to see the Deleted reference popup ("Originally referenced ?Q1A1 field was changed or deleted. Edit this rule to fix it."). You can:
- Edit the rule so it points to the field you want.
- Click OK here (this statement) or OK here and elsewhere (every statement with the same reference). This removes the
?but keeps the number, so the reference now points to whichever field has that number now. Use it only when that's the field you want.
A survey can't be launched while any ? reference remains: checkout reports an aytm Logic issue for that question.
💡 Tip: Give key fields an
@alias. Aliases stay the same however the survey is reordered, so logic that uses them never needs fixing.
Reference Modifiers
Append these letters to a reference to get the respondent's response, a comment, a position, an image, or a number instead of the field text.
| Syntax | Description |
|---|---|
| R | Response—text of the selected answer(s), e.g., [Q1r]. For open-ended questions it returns the typed text. Multiple responses are joined with commas and ", and" (adjusted to the survey language). |
| R1, R2... | The first, second… response, in the order the respondent gave them, e.g., [Q1r1]. |
| Rn | Number of responses, e.g., [Q1rn]. For an optional open-ended question it returns 0 if the respondent skipped it. |
| Rc | All comments, comma separated. |
| Rv | Response value—the numeric value of the response, e.g., [Q1SQ1rv]. Use it with Distribute (amount), Polarity Scale (0–100), Smileys (e.g., −2 to 2), and Stars (star count). |
| Ri | First image of the response(s). |
| c | Comment—open-ended text, e.g., [Q1c] or [Q1A1c] for an answer with a comment field. |
| v | Convert to a number. Add after c, p, or r1: cv, pv, r1v. The system reads digits until the first non-numeric character; if no number is found, it returns 0. |
| p | Position as a word ("first", "second"…) in which the item appeared to the respondent, e.g., [Q1A1p]. Returns empty text if the item wasn't seen. |
| pv | Position as a number (1, 2…), e.g., [show if Q5A5pv<4]. |
| i | Image, e.g., [Q1i] or [Q1A1i]. On a video question, shows the video thumbnail. |
| ix / is / ixs | Image shown expanded (x), scrollable (s), or both (xs). |
Range Shortcuts
Shortcuts let you list several items of the same question in a single reference. Write them with no spaces.
| Syntax | Description |
|---|---|
| , | Alternative "and" operator. [show if Q1A1,3,5] = Q1A1 and Q1A3 and Q1A5. |
| : | Alternative "and" operator—used for ranges. [show if Q1A1:3] = Q1A1 and Q1A2 and Q1A3. |
| . | Alternative "or" operator. [show if Q1A1.3.5] = Q1A1 or Q1A3 or Q1A5. |
| - | Alternative "or" operator—used for ranges. [show if Q1A1-3] = Q1A1 or Q1A2 or Q1A3. |
| Q1:3A1-2 | Multi-level shortcut. Equals (Q1A1 or Q1A2) and (Q2A1 or Q2A2) and (Q3A1 or Q3A2). |
⚠️ Note: Shortcuts only work inside one reference. To combine different questions, spell out
and/or:[skip to Q5 if Q1A1,5 and Q2A1]. In[Group ... balance ...]conditions, always spell out and/or instead of using shortcuts.
Operators and Functions
| Syntax | Description |
|---|---|
| and | "and" operator |
| or | "or" operator |
| not | Negative condition statement, e.g., [hide if not @influencer]
|
| = | Equal to. Text comparisons ignore upper/lower case. Two arrays are equal when they hold the same items, in any order. |
| != / <> | Not equal |
| > | Greater than |
| < | Smaller than |
| >= | Greater than or equal to |
| <= | Smaller than or equal to |
| + | Add. With text, joins the texts: [result = "Promoter " + "and influencer"]
|
| - | Subtract |
| * | Multiply |
| / | Division (returns decimal values) |
| ** / ^ | Power, e.g., [result = 36 ** 3]
|
| exp | Euler's number (e) raised to a power, e.g., [result = exp 3]
|
| ln | Natural logarithm, e.g., [result = ln 10]
|
| Round # | Round (standard). Add digits for decimal places: round 3.1415 = 3, round2 3.1415 = 3.14 |
| Ceil # | Round up: ceil 3.1415 = 4, ceil3 3.1415 = 3.142 |
| Floor # | Round down: floor 3.1415 = 3, floor1 3.1415 = 3.1 |
| in | Checks whether a value is in an array: [show if "first" in ar_1]. If both sides are arrays, it's true when every item on the left is in the array on the right. |
| like | Checks whether text contains other text: [show if Q1c like "Pepsi"]. If the right side is an array, it's true when the text contains any item (useful for a list of brand misspellings). If the left side is an array, it's true when any item contains the text. Matching is case-sensitive. |
| count | Number of items in an array, e.g., [n = count ar]
|
| rand #:# | Random whole number in a range, e.g., [rand 2:7] or [savedRandom = rand 1:100]
|
Variables and Arrays
For worked examples—a quiz score, respondent labels, matching spellings in open-ended answers—see How to Use Variables and Arrays in aytm Logic.
| Syntax | Description |
|---|---|
| [VarName...] | Introduce a custom variable. VarName can use A–Z, a–z, 0–9, and underscore. Each respondent has their own value. |
| [QuizScore = 0] |
Create a variable or set its value. The right side can be a calculation,
e.g., [result = 36 / 7].
|
| [QuizScore + 1] |
Add to a variable. Also works with -, *,
and /, e.g., [QuizScore - 5].
|
| [QuizScore] | Pipe the variable's value. |
| << |
Add to array—creates the array if it doesn't exist:
[ar << 1]
|
| , (array) |
Add more items to array: [ar << 1,2,3,4],
[ar_1 << "first", "second"]. Mixed numbers and
text are supported.
|
| | (array) |
Value at position in array (1-based): [ar3|3] pipes
the third item. [ar3] pipes the whole array, comma delimited. An array holds up to 500 items.
|
| shuffle |
Randomize the order of an array: [arr2 = shuffle arr1].
Add max to keep only some items:
[ar = shuffle ar max 2].
|
| reverse |
Reverse an array: [scores_reversed = reverse scores]
|
| unique |
Remove duplicates: [scores_unique = unique scores]
|
| sort |
Sort ascending: [scores_sorted = sort scores]. Descending:
[x = reverse sort scores]. Numeric arrays sort as numbers;
arrays with any text sort as text.
|
| join ... by |
Join array items with a separator: [join ar by " / "]
|
| oxford-join ... by |
Join items as a list: [oxford-join ar by "and"] gives
a, b, and c (two items: a and b).
|
| replace ... from ... to |
Replace every occurrence of text:
[replace Q1c from "-" to " "]
|
Display and Flow Commands
| Syntax | Description |
|---|---|
| [Show] | Show a field. Fields are visible by default, so this is rarely needed. |
| [Hide] | Hide a field |
| [Show if...] | Show a field if a condition is met |
| [Hide if...] | Hide a field if a condition is met |
| [Hide text] | Hide the field's text from respondents (it stays visible on the stats page). Useful to show only an image. Also [Hide text if...]. |
| [Show first / last...] | Show a number of first or last elements: [show first 3 Q1A], [show last 4 Q2E if Q1A1]
|
| [Skip to...] | Skip to a destination, e.g., [Skip to Q10]. [Skip to Exit] ends the survey and counts the respondent as a complete. |
| [Skip to... if] | Skip to a destination if a condition is met: [Skip to Q10 if Q5A2]
|
| [Skip to Q5 or Q7 or Q9] | Skip to a random destination the respondent can still enter. Ranges work too: [Skip to Q10-15] (use -, not :). If none is available, the respondent continues to the next question. |
| [Mask by...] | Mask a question based on selected answers to an earlier question: [mask by Q1] or [mask by @alias]
|
| [Rev-mask by...] | Mask a question based on non-selected answers to an earlier question |
| except | Leave items out of a mask or sort: [mask by Q1 except Q2A5]. Ranges (Q2A5-7) and lists (Q2A1,7) work. |
| [Glue...] | Keep elements together when randomized. [glue Q1A2,3,4] keeps them in that order; [glue Q1A2.3.4] randomizes their order within the block. |
| [Exclusive...] | Place on an answer option in a multi-select question. When it's selected, the listed options are cleared and grayed out: [exclusive Q1A1], [exclusive Q1A2,3]. Only options in the same question can be listed. |
| [Exclusive all] | Selecting this option clears and grays out all other options (e.g., "None of the above"). |
| [Sort by a-z ...] | Sort elements alphabetically (a-z or z-a): [sort by a-z Q1A], [sort by z-a Q1SQ], [sort Q1A by a-z except Q1A5]
|
| [Sort ... by ...] | Sort elements by array of positions: [CustomOrder << 4,3,2,1][sort Q2A by CustomOrder]. Create the array before the sorted question. |
| [Group...balance...max...] | Create nodes, group them together, show them randomly to respondents; optionally balance across variables and limit nodes per respondent. Example: [Group Q5-10 and Q11-12 and Q13-18 max 2]. |
| randfill / leastfill | Group assignment mode. The default, leastfill, prefers the nodes shown least often; randfill assigns nodes at random. |
| then | Initiate nested group logic. Inside parentheses, then sets the order of subgroups: [Group (Q1-3 and Q4-6 max 1 then Q7-9) and Q10-12 max 1]. See Nested Group Logic. |
| punch | Automatically record answer(s) for respondents without requiring them to view the question. Place it in the question being filled: [punch if Q1A3] on an answer, or [punch Q2A1 if Q1A3] in Q2. Add 5 as value or "n/a" as comment where the question type accepts a value or comment. See Punch Logic. |
⚠️ Note: If
[Skip to...]targets a question that the respondent can't enter because of[show if...]or[hide if...], the skip doesn't happen and the respondent continues to the next question after the one with the skip.
Terminate and Quota
| Syntax | Description |
|---|---|
| [Terminate if...] | Terminate a respondent based on criteria outside the Target Market page. Example: [Terminate if Q2A5] placed in Q2. |
| [Terminate if... after Q#] | Choose which question the check runs after: [Terminate if Q1A1 and Q3A2 after Q3]
|
| [Quota...] | Set specific quotas for respondents based on criteria outside the Target Market page. Example: [Quota Q1A3 max 50]. |
| [Quota... after / before Q#] | Choose when the quota is checked: [Quota Q1A3 max 50 after Q2]
|
⚠️ Note: Terminate and Quota logic is available if your plan includes it or after you complete the Custom Quota & Logic training. It must be placed in—and can only refer to—prequalification questions and Q1–Q3. A quota can't refer to a question that has its own show/hide logic. See Custom Quota Logic and Terminate Logic.
Reserved Variables
Reserved variables are filled in automatically. Use them for piping ([age]) or in conditions ([show if gender="f"]). Values are lower-case text codes.
System variables
| Variable | Description |
|---|---|
| [aytm_response_id] | Unique response identifier number—matches the first column in stats page exports. Can be used as an identifier for complex redirections. |
| [uuid] | Unique User ID (if available) |
| [var1] / [var2] / [var3] | First, second, or third custom variable passed through the survey link (if available) |
| [platform] | Respondent's operating system (windows, mac, linux, ios, android, other) |
| [device] | Respondent's device type (undefined, pc, mobile, tablet) |
| [browser] | Respondent's browser (chrome, opera, firefox, ie, electron, safari, edge, other) |
| [vr_collected] | Will be true if the respondent submitted a video |
| [completed] | Respondent's completion time (Stats page only). Example: completed < 2022-08-01 00:00:00 or completed > 2022-01-01 09:00:00
|
Respondent traits
| Variable | Description |
|---|---|
| [gender] | Respondent's gender (f, m; n is also available in the US, UK & Canada) |
| [age] | Respondent's current age (13–99) |
| [age_range] | Respondent's age range (13-17, 18-24, 25-34, 35-44, 45-54, 55-64, 65-74, 75+) |
| [income] | Respondent's household income, responsive to fielding country. US values: 0-25k, 25k-50k, 50k-75k, 75k-100k, 100k-200k, 200k+ |
| [education_level] | Respondent's highest education, responsive to fielding country. US: highschool, somecollege, technicaldegree, associatedegree, bachelorsdegree, mastersdegree, professionaldegree, doctoratedegree. General list: nocollege, somecollege, 2yrdegree, 4yrdegree, gradschooldegree, professionaldegree |
| [race] |
Respondent's race/ethnicity, responsive to fielding country. In the
US this is a list (whiteamerican, africanamerican, asianamerican,
nativeamerican, other), so use in:
[show if "asianamerican" in race]. See
Demographic Trait Reference Logic
.
|
| [hispanic] | Whether a US respondent is Hispanic/Latino (yes, no) |
| [employment] | Respondent's employment status (fulltime, parttime, freelancer, student, homemaker, retired, disabled, unemployed) |
| [career] | Respondent's career (acc/fin/bank, adv/design, agriculture, architecture, arts/ent, automotive, aviation, biotech, brokerage, cannabis (US only), carpentry, chemical, clerical, comms, computerhardware, computers, software, construction, consulting, consumerelectronics, consumergoods, edu, energy, engineering, envservices, fashion, food, freelance, government, healthcare, hospitality, hr, insurance, internet, it, publicsafety, legal, machinery, management, manufacturing, marketresearch, marketing/sales, military, mining, nonprofit, persserivices, pharma, printing, pubrelations, realestate, retail, security, logistics, smbusiness, telecom, transport, other, notemployed) |
| [relationship_status] | Respondent's relationship status (single, married, widowed, significantother, engaged, divorced) |
| [children] | Respondent's parental status—digit represents number of kids under 18 in household (0, 1, 2, 3, 4, 5+) |
| [children_age_and_gender] | Age(s) and gender(s) of respondent's children |
| [country] |
Respondent's country as ISO 3166 code. Example:
[show if country="CA" or country="FR"]
|
| [region] |
Respondent's region code. Example:
[show if country="US" and region="S"]
|
| [state] |
Respondent's state as ISO 3166 state code. Example:
[show if country="AR" and state="T"]
|
| [county] |
Respondent's county as FIPS code (US). Example:
[show if county="06037"]
|
| [zip] |
Respondent's zip code (US). Example:
[show if country="US" and zip="90001"]
|
| [msa] / [csa] / [dma] | Respondent's Metropolitan Statistical Area, Combined Statistical Area, or Designated Market Area code (US) |
⚠️ Note: Trait variables have a value only when the trait was collected for that respondent. See Demographic Trait reference logic.
Examples
| Example | What it does |
|---|---|
| [PQ1] | Reference to the first prequalification question |
| [Q1] | Reference to the first question |
| [Q1A1] | Reference to the first answer of the first question |
| [Q1SQ1A1] | Reference to the first answer of the first subquestion of the first question |
| [Q1E1SQ1A1] | Reference to the first answer of the first subquestion of the first entity of the first question (used in Competitive Topography and Quadrant questions) |
| [Q1i] | Reference to the image attached to the first question |
| [Q1A1p] | Position ("first", "second"...) of the referenced item |
| [Q1A1pv] | Position (1, 2...) of the referenced item |
| [show if Q1SQ1rv>2] | Show the question only to respondents who assigned more than 2 points to Q1SQ1 in a distribute question |
| [Q1cv] | Converted comment response to number of the referenced item |
| [Q1r] | Reference to all responses given by the respondent to the first question |
| [Q1r1] | Reference to the first response given to the first question |
| [Q1rn] | Number of responses chosen on the first question |
| [Q1r1c] | Comment entered by the respondent on their first response to the first question |
| [Q1rc] | All comments entered by the respondent on the first question |
| [Q1r1i] | Image associated with the first response chosen on the first question |
| [show if @promoter] | Show the field to respondents who selected the answer (or saw the question) where the alias @promoter was placed |
| [skip to Exit if Q1A1cv<18 or Q1A1cv>25] | End the survey if the number entered in the first field of a Forms question is below 18 or above 25 |
| [show if Q1rc='Pepsi'] | Show the field only if the open-ended response to Q1 was "Pepsi" (upper/lower case doesn't matter) |
| [QuizScore = 0] ... [QuizScore + 1 if Q3A2] | Keep a running quiz score: start at 0 and add 1 for each correct answer |
| [CustomOrder << 1,2,3,4] [CustomOrder = shuffle CustomOrder] [sort Q2A by CustomOrder] [sort Q3A by CustomOrder] | Randomize the answers of Q2 and Q3 in the same order |
| [punch Q2A1 if Q1A3] | Placed in Q2: records A1 for Q2 if the respondent selected A3 in Q1, without showing them Q2 |
| [Terminate if Q2A5] | Any respondents who select Q2A5 will be terminated after answering Q2 |
| [Quota Q1A3 max 50] | After 50 respondents have selected Q1A3, any further respondents selecting it will be terminated—the quota is full |
Rule Priority
When rules conflict, the higher priority wins:
- aytm Logic—the rules on this page.
- Skips set in the editor—navigation set up with the editor's skip controls (direct and random).
- Default flow—questions are shown in order, from first to last.