Question Type Calculated Field

From EpiHandy

Jump to: navigation, search

Calculated field is a fairly limited question type with fairly few functionalities.

You may use any answers of another question in this question type. All you have to do is to add a reference to one or more variables in the Default value field. Using this way of writing: {$VARIABLENAME$} 

NOTE! The variable name is CASE SENSITIVE

Contents

Use cases:

Count number selected in a list.

If you have a question where users should select one or more options (i.e. List w/Checkboxes)

To count number of options selected:

  1. Select question type: Calculated Value.
  2. In the field Default Value you can type one of the following:
    1. count -checked VARNAME_OF_QUESTION
    2. count -specified VARNAME_OF_QUESTION

Where VARNAME_OF_QUESTION has to be a question of type List w/Checkbox/Radiobutton where you want to count the number of options selected/specified. But mostly useful for checkbox, textbox.

Randomisation from a sequential list

What you have to do is add a new question with type Calculated Field.

Then in the default value field you add the following text:

random 1 count -checked varSequentialList

Where varSequentialList is the variable name of the question with the list from which a random.

It will then make a random number between 1 and how many household members are listed

Randomisation based on 2 numeric answers

If you have 3 questions, var1, var2, var3. Where var1 = 5 and var2 = 10, var should be a randomer number between 5 and 10.

What you have to do is add a new question with type Calculated Field. 

Then in the default value field you add the following text:

random {$var1$} {$var2$}

Prefillling of information from another question or parent form

Automatic fillin of names from household rooster into subform.

How to copy the text entered into the textbox of a listoption (i.e. household rooster) into a question on the subform for that particular option.

  1. Question Type: Calculated Field
  2. Default value: parent

Reusing information or data from one or more other question answers.

You may use any answers of another question in this question type. All you have to do is to add a reference to one or more variables in the Default value field. Using this way of writing: {$VARIABLENAME$}

NOTE! The variable name is CASE SENSITIVE

If you have a form with the following variables: var1=A, var2=B, var3, var4=D, var5=E, var6=F, var7=G, var8

  • in var3, you want a summary of var1 and var2
  • In default value type the following: {$var1$} and {$var2$}, the answer would be: A and B
  • in var8, you want a summary of more, {$var3$} is not {$var4$} and {$var5$}, the answer would be A and B is not D and E
  • For all of them use Question Type: Calculated Field