Formula basics


Formulas are a special language used on Conjoint.ly to perform tasks such as:

  • Calculating revenue in the simulator
  • Weighting respondents

Algebraic functions

Algebraic functions perform basic mathematic operations:

OperationSyntaxExample
Additionx+y20+15 = 5
Subtractionx-y10-3 = 7
Multiplicationx*y7*3 = 21
Divisionx/y10/2 = 5
Exponentialx^y4^2 = 16

Comparison operators

Comparison operators are used to compare two variables. Comparisons operators always return TRUE or FALSE.

OperationSyntaxExample
Equalsx==y5==10 = FALSE
Not equalsx!=y10!=3 = TRUE
Greater thanx>y5>19 = FALSE
Equal to or greater thanx>=y4>=4 = TRUE
Less thanx<y6<10 = TRUE
Equal to or less thanx<=y5<=1 = FALSE

Boolean operators

Boolean operators are used to combine or exclude comparison operations. Boolean operators always return TRUE or FALSE.

OperationSyntaxExample
NOT!x!(10==5) = TRUE
ANDx&yTRUE&(10==5) = FALSE
ORx|y(10<4)|(10>2) = FALSE

Built-in functions

if/ifs functions

These functions allow for different return values depending on whether a condition is true or not

FunctionDescription
if('condition', 'then', 'else')Checks condition and returns a value if it is true or another value if it is false
ifs('condition_1', 'then_1', 'condition_2', 'then_2',..., 'else')Returns a value that corresponds to the first true condition or the else value if other conditions are false

Respondent information functions

These functions are used to pull respondent information from for use in formulas

FunctionDescriptionExample
GETvariable(variable_name)Returns the GET variable specified by variable_name. variable_name should be the name of the variable quoted in single quotation marks. If none is supplied, returns NULL.GETvariable('platform')
externalVariable(variable_name)Returns value of the externally uploaded variable specified by variable_name. If none is supplied, returns NULL.externalVariable('platform')
segregation(scenario_name)Returns the segment the respondent was assigned via the segregation feature within the scenario specified by scenario_namesegregation('baseline')
respondentInfo('variable_name')Returns information automatically collected about a respondent.respondentInfo('baseline')

The list of valid variable names when returning respondent information using respondentInfo are:

Variable nameDescription
ipReturns the IP of the respondent.
locationCountryReturns the country of the respondent.
locationRegionReturns the region recorded for the respondent.
deviceReturns the device the respondent completed the survey on.
localeReturns locale recorded for the respondent.
idReturns the id used for the respondent. Respondent id’s are unique for each respondent in a survey, but the same respondent completing multiple surveys will have different id’s for each survey

Answer functions

These functions are used to access respondent answers.

FunctionDescriptionExample
answer(question_id, [item_id], [stimulus_id])Returns the responses in the question specified by question_id. item_id is an optional input to retrieve answers to an item in the question. stimulus_id is an optional input to retrieve answers to a particular stimulus in a monadic block.answer(1559253)
bottom(question_id, limit, [stimulus_id])Returns the N items the respondent placed at the bottom of the list in the question specified by question_id. N is determined by limit.bottom(1549283, 2)
top(question_id, limit, [stimulus_id])Returns the N items the respondent placed at the top of the list in the question specified by question_id. N is determined by limit.top(1549283, 2)
count(question_id, [stimulus_id])Returns the number of choices selected by respondents in the question specified by question_id. Function only works with multiple choice questions.count(1559253)
npsStatus(question_id, [stimulus_id])Returns the net promoter status (detractor, neutral, promoter) for Net Promoter Score questions. Specify question using question_idnpsStatus(1557233)