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
  • meyerlemon's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 1 month ago #194212 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?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #194220 by Joffm
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)}

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • meyerlemon
  • meyerlemon's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 1 month ago #194270 by meyerlemon
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
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #194275 by Joffm

in the Equation field under Logic > Equation?

Do you mean the "question validation 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.

Lime-years ahead

Online-surveys for every purse and purpose