Help Center Add Question Calculation Formula Calculation Formula Application Scenario 1

Calculation Formula Application Scenario 1

SurveyMars calculation formulas let target questions be auto-calculated or filled from other questions or system fields. Supported behaviors include multi-select same selection, reverse selection, referencing option fill-in text, and using default values in calculations—reducing duplicate setup and speeding up survey logic. Click to see examples.


Overview

Calculation formulas assign or compute values for the current question at edit time or when answering, based on existing question answers or system fields. Three typical uses: auto-select or reverse-select current question options from a previous multi-select, reference fill-in or option fill-in content in other questions, and include default values in calculations (e.g., q2=[q1]+1: if question 1 has default 10, question 2 shows 11).


Where to Find It

On the survey edit page, select the target question and find the "Calculation formula" area in the right-hand question settings to configure the formula.

Calculation formula or question expression in question settings


How to Use

1. Multi-select same selection (auto-select same options as previous question)

1. Enter the formula in the target multi-select’s question expression, e.g. q2 = [q1].


Same-selection formula setup


2. The system reads [q1]’s selected items as an array and compares them to q2’s options one by one; if the option text matches exactly, that option is auto-selected. One formula handles the whole same-selection linkage without writing separate formulas per option.

Same-selection formula result


3. Ensure [q1] and q2 have identical option text; otherwise options will not match and will not be auto-selected.


2. Multi-select reverse selection (auto-select options not selected in previous question)

1. Enter the formula in the target multi-select’s question expression, e.g. q3 = [q1_reverse].


2. The system reads [q1]’s selected items, compares with the current question’s options, and auto-selects the options that were not selected in q1. One formula implements reverse selection without separate formulas per option.


Reverse-selection formula setup and result

3. [q1] and q3 must also have identical option text; if q1 does not have an option, the corresponding option in q3 will not be selected.


3. Referencing option fill-in content

1. Enable "Option allows fill-in" on the source question; to reference that fill-in in the target question’s formula, use [q1_1_text] (use the actual question number and fill-in index for your survey).


2. For example, set q5 = [q4_7_text]. When the respondent selects "option 7 of question 4" and fills in the text, the target question will show "option label, fill-in content".


Referencing option fill-in content

4. Default values in calculations

1. Set default values on the source question (default text for fill-in, default option for choice questions).


2. Set the calculation formula on the target question, e.g. q7 = [q6]*3. If [q6] has default value 10, q7 will show 30 as soon as the response page loads, without the respondent answering question 6 first.


Default value in calculation

Configuration Reference

Question reference format: When referencing other questions in a formula, wrap the question ID in square brackets, e.g. [q1], [q2]. When using functions like CONCATENATE, question IDs must also be in square brackets.


SEARCH / FIND and similar functions: Use double quotes for search strings, e.g. FIND("blue",[q1]). Single quotes may cause the formula to save incorrectly or not run when answering; use double quotes consistently.


Changing question type: Changing the question type clears any calculation formula set on that question. A confirmation dialog appears: "Changing question type will clear the calculation formula. Continue?" Confirm to proceed; this avoids losing the formula by mistake.


Important Notes

- Same selection [q1] and reverse selection [q1_reverse] require the source and target questions to have identical option text; otherwise matching will fail.


- Use [q1_1_text] and similar forms to reference option fill-in content; question number and fill-in index must match your actual question setup.


- Use double quotes for keywords, delimiters, etc. in formulas to avoid save or runtime issues—e.g. IF([q3]=="yellow",1,0)—and to avoid formula errors or formulas not taking effect.


FAQ

Q: What happens to the calculation formula when I change the question type?


A: Changing the question type clears the formula configured for that question. A confirmation dialog appears: "Changing question type will clear the calculation formula. Continue?" The formula is cleared only after you confirm; choose whether to continue based on your needs.


Q: Should I use single or double quotes for question references or keywords in formulas?


A: Use double quotes consistently. For SEARCH, FIND, and similar functions, and for TEXTSPLIT delimiters, single quotes may cause the formula to display incorrectly after save or not run when answering; the sample formulas in the docs use double quotes.


Q: Same selection q2=[q1] or reverse selection q3=[q1_reverse] isn’t working. What could be wrong?


A: Check that the source and target questions have identical option text (including spaces and punctuation). Same/reverse selection match option text line by line; any difference prevents auto-selection. Also, if the source question does not have an option, the corresponding option in the target will not be selected for reverse selection.


How helpful was this article?