Value assignment functions

This page is an extension of the Value Assignment basic functionality, if you are not yet familiar using the value assingment, please read here.

Disclaimer: If you have a professional user license, you can use all functions described in this page. However if you are stuck, you need an extended support contract (SLA) to get our assistance. Survalyzer product support does not include value assignments. Contact our sales team to get a extended support contract.

Math.js functions

As a foundation of the value assingment element we use math.js. There are out-of-the-box functions you can use. In case, the following listed functions do not fulfill your requirements, you may search for more in math.js function reference: https://mathjs.org/docs/reference/functions.html

Arithmetic

FunctionDescriptionExample CallExample Result
+adds termssum=3+25
subtracts termsdifference=3-21
*multiplies termsproduct=3*26
/divides termsquotient=3/21.5
%calculates the modulusmodulus=3%21
^exponentiates termssquare=3^29
sqrtcalculates the square rootresult=sqrt(9)3
abscalculates the absolute valueresult1=abs(-5)
result2=abs(5)
5
5
roundrounds number to decimalresult=round(2.35,1)2.4

Statistics

Download JSON of statistics reference survey and import it into your workspace.

FunctionDescriptionExample CallExample Result
sumcalculates the sumsum(2,3,5)10
meancalculates the meanmean(2,3,5)3.3333…
mediancalculates the medianmedian(2,3,5)3
stdcalculates the standard deviationstd(2,3,5)1.5275…
variancecalculates the variancevariance(2,3,5)2.3333…
mincalculates the minimum valuesmin(2,3,5)2
maxcalculates the maximum valuemax(2,3,5)5

Randomisation

Download JSON of randomisation reference survey and import it into your workspace.

FunctionDescriptionExample CallSurvey Reference
randomreturns a real number between min (included) and max (excluded)random(min,max)
randomIntreturns an integer number between min (included) and max (excluded)randomInt(min,max)Section 2 of randomisation survey
pickRandomreturns a randomly chosen element out of the given listpickRandom([var1,var2,var3])Section 1 of randomisation survey
shuffleshuffles the values of a matrixshuffle([var1,var2,var3])

Texts

Download JSON of texts reference survey and import it into your workspace.

FunctionDescriptionExample CallExample Result
concatconcatenates textsconcat("8005"," ","Zürich")“8005 Zürich”
equalscompares texts and returns either “true” or “false”equals("8005","Zürich")false
containscompares substring in texts and returns either “true” or “false”contains("or","World")true
countcounts the characters of a textcount("8005 Zürich")11
[start:stop]returns a substring, beginning at “start” and ending at “stop” (number of character)"8005 Zürich"[1:4]“8005”
indexOfreturns the start position of a search string (be aware: first character is 0)indexOf("8005 Zürich","Zürich")
indexOf("8005 Zürich","Utrecht")
5

-1
subsetreplaces characters at defined positionsubset("8000 Zurich",index(4:7),"5 Zü")“8005 Zürich”

Data Transformation

Download JSON of data transformation reference survey and import it into your workspace.

FunctionDescriptionExample CallSurvey Reference
date2numberreturns timestamp (number of milliseconds) for a given datedate2number(varDate)Section 1 of data transformation survey
datetime2numberreturns timestamp (number of milliseconds) for a given time (incl. a date)datetime2number(varDateTime)
todayreturns current date (data type date)today()Section 1 of data transformation survey
addDaysadds number of days specified to a given date (data type date)addDays(today(),-7)
parseNumberreturns integer number enclosed in textparseNumber(varText)Section 2 of data transformation survey
parseRealreturns real number enclosed in textparseReal(varText)
convertToStringconverts given number into textconvertToString(varNumber)Section 2 of data transformation survey
binreturns binary value of number (data type text)bin(varNumber)
hexreturns hexadecimal value of number (data type text)hex(varNumber)
csvToNumberArrayconverts a CSV string into a number array (data type matrix)csvToNumberArray('34,34,123,43')
csvToStringArrayconverts a CSV string into a string array (data type matrix)csvToStringArray('34, 34, 123 , 43')
toJSONconverts JSON string into JSON variabletoJSON(varText)

Counters

Download JSON of counters reference survey and import it into your workspace.

FunctionDescriptionExample CallSurvey Reference
count_startedcalculates the number of interviews with status “InProgress”survey.count_startedSection 2a of randomisation survey
count_completedcalculates the number of interviews with status “Completed”survey.count_completedSection 2a of randomisation survey
countInterviewscalculates the number of interviews that meet the custom conditioncountInterviews(customCondition)Section 1 of counters survey

Survey Element’s Controls

Download JSON of controls reference survey and import it into your workspace.

FunctionDescriptionExample CallSurvey Reference
setSurveyFieldsReadOnlysets text fields or multiple choice checkboxes into read only modesetSurveyFieldsReadOnly([VariableName])
hide (back button)hides the back buttonBackButton("hide")Section 2 of controls survey
hide (next button)hides the next button for a defined number of secondsNextButton("hide",5)Section 1 of controls survey
click (next button)automatically clicks the next button after a defined number of secondsNextButton("click",5)Section 1 of controls survey
hideandclick (next button)hides the next button for a defined number of seconds and then automatically clicks on itNextButton("hideandclick",5)Section 1 of controls survey
getChoiceTitle(“[VarName]”,”[Value][Variable],[true]returns the choice text as either in plain text format or as a comple htmltitle with html
getChoiceTitle(“q1”, “1”)
getChoiceTitle(q1, q1) // selected option
title without html
getChoiceTitle(“q1”, “1”, true)
getChoiceTitle(q1, q1,true) // selected option

Special Features

Download JSON of custom function and if-then-else reference survey and import it into your workspace.

Download JSON of matrixto reference survey and import it into your workspace.

FunctionDescriptionExample CallSurvey Reference
if-then-else statementallows conditional executions of actionscustomCondition ? thenAction : elseActioncustom function and if-then-else reference survey
isNullOrUndefined
isNull
isUndefined
used in conditions to check if variable is null or undefinedisNullOrUndefined(varText)
isNull(varText)
isUndefined(varText)
custom function and if-then-else reference survey
custom functionscan be used for recurrent actionsnaFilter(x) = x!=0 and x!=null
real3 = mean(filter([var1,var2,var3],naFilter))
custom function and if-then-else reference survey
list functionhides non-selected answers of a list in follow-up questionslist(choice) = answer(concat('brand_',choice.code)) == 1 ? true : false
setChoicesVisibility('bestbrand',list)
JSON of list function reference survey
getSurveyLinkgenerates a personal link for a certain surveylink=getSurveyLink(123)JSON of survey link refernce survey
matrixtoflatarrayreturns a one dimensional matrix (=array) out of a multi dimensional matrixmatrixtoflatarray(varMatrix[1:end,2])matrixto reference survey
matrixToHtmlgenerates HTML table code from a matrix variablematrixToHtml(varMatrix)matrixto reference survey
Updated on December 12, 2022

Article Attachments

Was this article helpful?

Related Articles

Need Support?
Please login to your Survalyzer account and use the "Create Support Request" form.
Login to Survalyzer