Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Condition from result of an equation

  • arnaudbore
  • arnaudbore's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 10 months ago #199687 by arnaudbore
Condition from result of an equation was created by arnaudbore
Dear experts,

I would like to know if there a way to create a condition from the result of an equation question.

I have a equation question that gives me the age of a participant.
I would like the next question to appear if age between 12 and 49.

So far, condition editor put an OR instead of a AND...

Thank you for your help
Arnaud
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #199690 by Joffm
Replied by Joffm on topic Condition from result of an equation
And therefore we do not usethe condition builder anymore.
If you want to use it, you have to create a new scenario to have the AND condition.

Nowadays we use Expression Manager/Script.
Or do you use a LimeSurvey version that doesn't have this included?

I have a equation question that gives me the age of a participant.

Did you calculate from his date of birth, or how?

Okay, the equation may be called "age"
Here you just have to type into your relevance equation of the question:
age>11 and age<50

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #199691 by holch
Replied by holch on topic Condition from result of an equation
I would forget about the condition editor as quickly as possible. You obviously already know how to use Expression Manager/Script, as you are using it for an equation question.

Use relevance equations instead of conditions. Much more flexible and a lot quicker in my opinion.

Just put an equation in the relevance equation that will show it only if respondents are between 12 and 49.

Code could look like this (not tested and you'll have to adapt it to your survey of course):
Code:
age >= 12 AND age <=49

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #199692 by holch
Replied by holch on topic Condition from result of an equation
Ok, Joffm beat me by a couple of minutes. ;-)

Same approach, slightly different formula. Should both work.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • arnaudbore
  • arnaudbore's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 10 months ago - 3 years 10 months ago #199695 by arnaudbore
Replied by arnaudbore on topic Condition from result of an equation
Thank you guys for all your answers. It works pretty well but for some reasons if I add another condition, it doesn't seem to take into account the first condition, neither the third condition but when the second condition are met the question show up. :silly: :blink:

{(age>11 and age<50) or (age>49 and (QMenopause=="Y" and QMenopauseYear=="N")) or (age>49 and QMenopause=="N") }
Last edit: 3 years 10 months ago by arnaudbore.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #199697 by holch
Replied by holch on topic Condition from result of an equation
What is the first, second and third condition?
1. (age>11 and age<50)
2. (age>49 and (QMenopause=="Y" and QMenopauseYear=="N"))
3. (age>49 and QMenopause=="N")

?

Please provide a LSS file with only the questions that are relevant for the problema so we can check.

I don't see an obvious problem in your code right now.

Do the 1st and 3rd condition work on their own? Have you tested them without the other conditions, just to make sure that each single condition works?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • arnaudbore
  • arnaudbore's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 10 months ago #199698 by arnaudbore
Replied by arnaudbore on topic Condition from result of an equation
I checked the first one alone and it worked. Here is the lss file.


Thank you in advance for your help.

Arnaud
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #199700 by holch
Replied by holch on topic Condition from result of an equation
My first guess would be that the problem is that you are showing all questions on one screen. Not the best approach anyway.

But I'll need to do some research to check this.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #199701 by holch
Replied by holch on topic Condition from result of an equation
And which is the question with the problem? You have sent a file with a lot of questions and so far I couldn't find the one with the relevance equation that doesn't work:
Code:
{(age>11 and age<50) or (age>49 and (QMenopause=="Y" and QMenopauseYear=="N")) or (age>49 and QMenopause=="N") }

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #199703 by holch
Replied by holch on topic Condition from result of an equation
Found it. If you look at the relevance equations before you'll see the code highlighting. The relevance equation in the question "G3Q0012" has no highlighting at all. This usually means it hasn't been recognized as an equation.

So the problem was probably that you had a space at the end of your equation code and thus LS didn't understand it.

Your version:


Without the space at the end:


Haven't checked the actual function of the relevance equation, but the way it was it couldn't work, because the conditions in the relevance equation were not considered.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • arnaudbore
  • arnaudbore's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 10 months ago #199704 by arnaudbore
Replied by arnaudbore on topic Condition from result of an equation
Sorry, here is a short version of the survey.
The topic has been locked.
  • arnaudbore
  • arnaudbore's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 10 months ago #199706 by arnaudbore
Replied by arnaudbore on topic Condition from result of an equation
Even with this modification, the conditions 1 and 3 are not working properly.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose