Average
The ‘Average’ formula is used to average all responses for any given question. Formula parameters include:
Question Name
Precision of Calculation (optional, but required if a third parameter is added)
Type of Average (optional, but required if more parameters are added)
1 → Average all the values
2 → Average last n days (4th parameter is required of type number of days)
3 → Average n days starting from a specific date (4th parameter is number of days, 5th parameter is a date value)
4 → Average n days ending on a specific date (4th parameter is number of days, 5th parameter is date value)
5 → Average last n responses (4th parameter is number of responses)
6 → Average n responses starting from a specific date (4th parameter is number of responses, 5th parameter is date)
7 → Average n responses end on a specific date (4th parameter is number of responses, 5th parameter is date)
8 → Average since specific date (4th parameter is date)
9 → Average until a specific date (4th parameter is date)
10 → Average between start date and end date (4th parameter is a date and 5th parameter is a date)
Based on the option selected in 3rd parameter (may or may not be required)
Based on the option selected in 3rd parameter (may or may not be required)
Note: If the 3rd parameter is part of the function call, then the corresponding parameters corresponding to that option become necessary.
Example:
Iff
The ‘Iff’ formula is used to evaluate a certain condition and then further evaluates a formula based on how the condition is evaluated. Parameters include:
The condition to evaluate. This condition should evaluate to true or false
The logic to evaluate if the condition is true
The logic to evaluate if the condition is false
Examples
Iff((14 - 7) > 0, DateDiff('today', ‘yesterday', ‘h'), 50 / 2)
The above formula will evaluate if the condition “14 - 7 > 0” is true or false
If true, it will evaluate “DateDiff(’today’, ‘yesterday’, 'h')
If false, it will evaluate “50 / 2”
Iff(ResponseExists([RadioQ1]), [RadioQ1] < 1, false)
The above formula will evaluate the condition “ResponseExists([RadioQ1])”
If true, “[RadioQ1] < 1” will be evaluated
If false, “false” will be evaluated
Iff(Contains([QuestionOne], 2), 1, 0)
The above 'Iff' formula will evaluate if the condition “Contains([QuestionOne], 2)” is true or false
The 'Contains' formula will get the last response for the question “QuestionOne” and check if ‘2' was one of them. If ‘2’ was one of them the logic will return TRUE and if '2’ was not one of them the logic will return FALSE.
If true, it will evaluate “1”
If false, it will evaluate “0”
DateDiff
The ‘DateDiff’ formula is used to evaluate the difference between two Date (and Time, if available). Parameters include:
The Date (and Time, if available) from which the other date will be subtracted from.
The Date (and Time, if available) which will be subtracted from the first parameter.
For the above two parameters, the date can be optionally specified as the following strings:
'now' → Date and time at the moment logic is evaluated
'today' → Date on which the formula is evaluated
'yesterday' → Yesterday’s date (no time component)
'tomorrow' → Tomorrow’s date (no time component)The format in which the result is required
The format can be:
'd' → total days
'h' → total hours
'm' → total minutes
's' → total seconds
Examples:
DateDiff('yesterday', ‘now', 'm')
This calculates the total minutes between yesterdays date and the date and time right now.
If the yesterdays’ date is 07/10/2023 and we are evaluating this function at 07/11/2023 at 4:07pm then the result should be about: -2407.5039294216667
Contains
The ‘Contains’ formula is a TRUE/FALSE statement used to check if a particular option was selected in a checkbox question type. In CMS (platform v1), the way to do that is to write something like this: [checkboxq(value)] == 1. This has been changed up in V2. The new formula to check if a checkbox contains a specific value is:
Contains([questionName], 2)
This formula excepts two parameters:
The variable/question name
The value to check
Examples:
Contains([CheckboxQ1], 3)
The formula will get the last response(s) for the question “CheckboxQ1” and check if ‘3' was one of them. If ‘3’ was one of them the logic will return TRUE and if '3’ was not one of them the logic will return FALSE.
Checkbox Syntax
Checkbox syntax from CMS is now supported. [CheckboxQuestion(1)] will result in 0 if the option with value “1” was not selected by participant and vice versa. This syntax doesn’t support default value format such as [RadioQuestion:-999] (which will result in a default value of -999 if no value was found for the question “RadioQuestion”]
ResponseExists/Exists
This formula is used to check if a particular question has been recorded in the DB with a response or not. This formula accepts one parameter which is the question name. The formula returns true if a response was found and false if a response was not found.
Example
ResponseExists([RadioQ])
Exists([RadioQ])
last or [*]
The constructs last() and [*] existed in CMS but they don’t exist in V2.
Default Values
Default values (applied when a response for a question cannot be found) can be defined in the declaration of question name followed by a colon “:”.
Examples:
[colorblue:-1] → Value assumed for the variable “colorblue” is -1 if no response found in the db.
[study_startdate:2100-01-01] → Value assumed for the variable “study_startdate” is 2100-01-01 if not value found.
[RadioQ1:0] → If no response found, the value for “RadioQ1” is assumed to be 0.
Home | Submit a Ticket | SCC | Privacy