- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Setting Default Value with Calculation from Previous Fields
- meyerlemon
- Topic Author
- Offline
- New Member
Less
More
4 years 2 months ago #194212
by meyerlemon
Setting Default Value with Calculation from Previous Fields was created by meyerlemon
Hello,
I'm working on a survey with patient data and have two numeric fields for height and weight. I'd like to set the default value of another field, BMI, with the BMI calculation using those two fields. So far I haven't had any luck doing so. Could someone point me to resources on how to do this?
I'm working on a survey with patient data and have two numeric fields for height and weight. I'd like to set the default value of another field, BMI, with the BMI calculation using those two fields. So far I haven't had any luck doing so. Could someone point me to resources on how to do this?
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12888
- Thank you received: 3965
4 years 2 months ago #194220
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Setting Default Value with Calculation from Previous Fields
Hi,
in my opinion you do not want to set the BMI value as default of another field?
Why should you do that?
That the respondent may change it?
I think you want to store this value in the dataset, maybe display it to the respondent.
So create a question of type equation, where you enter the formula
{weight/(height*height)}
where "weight" and "height are the question codes.
If the codes of these two questions are "Q1" and "Q2", it is
{Q1/(Q2*Q2)}
Hopefully with the correct units.
Have a look at this sample survey
manual.limesurvey.org/Expression_Manager...loring_and_Equations
and read about Expression Manager. (which in version 4.x. is called "Expression script")
manual.limesurvey.org/Expression_Manager
Joffm
And if you really want to prefill a third question, change the equation to
{Q3=weight/(height*height)}
in my opinion you do not want to set the BMI value as default of another field?
Why should you do that?
That the respondent may change it?
I think you want to store this value in the dataset, maybe display it to the respondent.
So create a question of type equation, where you enter the formula
{weight/(height*height)}
where "weight" and "height are the question codes.
If the codes of these two questions are "Q1" and "Q2", it is
{Q1/(Q2*Q2)}
Hopefully with the correct units.
Have a look at this sample survey
manual.limesurvey.org/Expression_Manager...loring_and_Equations
and read about Expression Manager. (which in version 4.x. is called "Expression script")
manual.limesurvey.org/Expression_Manager
Joffm
And if you really want to prefill a third question, change the equation to
{Q3=weight/(height*height)}
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- meyerlemon
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
4 years 2 months ago #194270
by meyerlemon
Replied by meyerlemon on topic Setting Default Value with Calculation from Previous Fields
Thank you so much for your help! I have never used equation question types before, and was just curious - in order to save just the BMI value, would I copy {weight/(height*height)} in the Equation field under Logic > Equation? I'm just trying to ensure that's the value saved.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12888
- Thank you received: 3965
4 years 2 months ago #194275
by Joffm
This is something different. Here you enter an equation to validate the question, e.g. (Q1<10) OR (Q1>60), to get only very small or very high ages, or whatever.
Your equation you enter in the question text of the equation question.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Setting Default Value with Calculation from Previous Fields
Do you mean the "question validation equation"?in the Equation field under Logic > Equation?
This is something different. Here you enter an equation to validate the question, e.g. (Q1<10) OR (Q1>60), to get only very small or very high ages, or whatever.
Your equation you enter in the question text of the equation question.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.