Using Last() to get the most recent Response
How to use the Last() response to a question or a previous survey to direct the current survey
formula example:
The Last() Response option is used to pull a Participant’s last Response to a particular Question. This enables researchers to use data from previous surveys to inform algorithms and formulas. See example below.
The example below referencing question “gender” there are two (2) values being shown: 0 = Female, 1 = Male. In the case that the Participant has answered this question multiple times, using the formula “last([gender])” will pull the most recent Response.
last([gender])
Variable: gender (compatible Question Type: Radio, Dropdown, or ButtonList)
Responses: [Text: “Female” Value: 0], [Text: “Male” Value: 1]
Multi Value Field (checkbox)
Not currently supported for last(), will currently match on any prior matching values
How to only show a Question if previous Response is a given Value
Accessing the most recent Value outside of an Assessment
Branching Logic Formulas can be used outside of Assessments for features such as Formula-based Stages and enabling Assessments based on Formula Logic.
With those elements of Study design, it can be important to access the most recent Response to specific Questions to enable specific Study behavior. This is done by combining the Formulas for “outside of the current Assessment” with “most recent Response value.”
The format is shown here:
last([[*]var_name])
If a Question is available to the Participant multiple times, as in from Participant-Initiated Events or during a Daily Assessment, then only the most recent value will be used for branching logic calculations in this format.
Instructions for Using Single-Value or Multiple-Value Fields in Formulas
Click the Assessment tab, select desired Assessment, and then open the Question that needs to be shown or hidden. In the “Formula” area, add the desired logic. Examples are below.
Single Value Field (Dropdown, Radio, Slider, etc)
When a Question type has single Value Responses (Radio, Dropdown, Slider, ButtonList), the CMS User should input a series of Responses. Clicking the ‘Add+’ button will add an additional row for a Response Text and its Value.
formula example:
The image below shows a Dropdown item [Test_Dropdown] that has four Responses, with the assigned Values 0, 1, 2, and 12. The ‘Formula’ field is also displayed where a Formula can be entered to determine the behavior of Questions during the Assessment.
The numeric Values of each Response should be carefully set because this is the data that will be downloaded in the dataset. Values for each Response must be assigned for the Responses to be used in Formulas, or for the Values of Responses to be available in Data Reports.
The image below shows branching logic that can be used to skip or ask specific Questions based on previous Responses in a survey. Additional Questions may be presented to the Participant, based on the answer provided for the Dropdown Question, Test_Dropdown.
If no Formula is added to a Question, it will always be asked during that survey.
Adding a Formula for a Question establishes conditions for when that Question should be shown.
In this example, the Question [Test_Dropdown] is shown every time the Assessment is taken.
The Question [Test_Radio] will only be presented during the Assessment if the Value Response to [Test_Dropdown] = 12.
Equality operators (>, >=, <, <=) can be used to allow multiple Response Values to a question to trigger a later question.
Changing the formula for Test_Text_Area
[Test_Dropdown]==1
to
[Test_Dropdown] >= 1
will display the Question when the Response to Test_Dropdown is Value 1, 2, or 12.
Multi Value Field (Checkbox)
Shown below is an example Checkbox Question that has possible Responses with Values 1, 2, 3, 4, 5, and 6. When the Question appears in an Assessment, the Participant will be allowed to select any or all of the possible Values for this Question.
Formula does not check the value of the Checkbox Question. Instead, it checks each of the possible Values has been selected: 1 = true (selected), 0 = false (not selected)
formula example:
The displayed example shows each of the following Questions for any of the Values that were selected and checked for later.
It is also possible to check that Values were not selected using the following example:
[And10Q5(2)] == 0
Using the example above: Responding to the Question And10Q5 with the Response Values 1, 2, and 3 will meet the Formula requirements for Questions And10Q1 and And10Q2 to be shown, but Questions And10Q3 and And10Q4 will not be shown during that Assessment.
Instructions for Enabling a Specific Event using Branching Logic:
Select an Assessment for an Event in the Events tab, then add a Setting and choose ‘Branching Logic’. In the “Formula” area, add the desired logic. The associated Assessment will be available if stored data Responses meet the formula conditions.
Instructions for Stages of End type ‘Formula’:
Click the Events tab, then when creating a new Stage, under “type” choose ‘Formula’. In the “End Date Formula” field, add the desired branching logic. This can be simple (e.g., [startstudy]== 1; when the Start Study question is answered yes (1), the app will move to the next Stage). This will trigger if any stored Participant responses meet the formula conditions, and missing values will default to false (thus not triggering a stage change on those variables).
formula example:
Complex logic: datediff("today",[study_startdate], "d", true, true) >= 1 or [skip_to_next_stage]==1
explanation:
This logic will move to the next stage if:
the Participant has been in the study a number of days is > 0, OR
the Participant responded to the Question [skip_to_next_stage] with Response Value 1
Use the datediff() method to compare today’s date to the Question [study_startdate], with params set to honor negatives and using local time, then advance the stage if the days (“d” param) are at least 1, or if the “skip_to_next_stage” variable has a Response Value of 1.
How to create a "circular stage" path
Instructions:
To create a circular stage (a stage that can loop back to a previous stage (e.g., Pre-Quit, Post-Quit), add logic to trigger that transition to the “End Date Formula” in Stage. In addition, add a stage setting of “Branching Logic” type, and add the matching criteria and stage to loop back. The tricky bit is that it will loop directly back if you do not add some logic to the looped stage to prevent that immediate loop.
For a simple example, we’ll have stage A and B.
End Date Formula example for stage A:
last([advance_to_stage_b]) == 1 and
(last([return_to_stage_a:0])==0 or
datediff(last([advance_to_stage_b_date]),last([return_to_stage_a_date]),"d",true) > 0)
explanation:
Check the user selected to advance, then check to make sure that either the user has never selected to go back to stage yet or if they have, that the date they selected for returning is not greater than the selection to advance. This second part will prevent an immediate loop back.
End Date Formula example for stage B:
last([return_to_stage_a]) == 1 and
datediff(last([return_to_stage_a_date]),last([advance_to_stage_b_date]),"d",true) > 0
explanation:
check that the user selected to return, then check to make sure the date of the return selection is greater than the last time the user selected to advance . This second part will prevent an immediate loop back.
Branching logic example for stage B:
last([return_to_stage_a]) == 1 and
datediff(last([return_to_stage_a_date]),last([advance_to_stage_b_date]),"d",true) > 0
explanation:
this will use the exact same logic in this simplistic instance for branching back to stage A, but if there were multiple stages to loop to you would only use the specific logic for looping to that stage. If no branching logic matches, then the next stage in order will start or the study will end.
note:
always add last() for stage change formulas if you are not concerned about checking all prior instances. The default is to check all collected data and this may become slow as the user accumulates more data.
Creating and Using the Random Number Generator
The Random Number Generator Question, requires a minimum and maximum value (Note: the user can also select decimal places for the random number). An example is shown below for a Random Number Generator Question with Minimum value 0, Maximum value 2, and 0 decimal places. This will generate a number that is between 0 and 2.
The randomly generated number can be used to drive intervention content.
The Random Number Generator can be added to the Assessment in order. It is possible to have multiple Random Number Generator Questions within a single assessment.