- Posts: 11
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
IF equation to display specific feedback over the answers
- Emma_F
- Topic Author
- Offline
- New Member
Less
More
5 years 8 months ago #172613
by Emma_F
IF equation to display specific feedback over the answers was created by Emma_F
Hi there, I'm trying to figure out how to make a conditional equation to display different feedbacks for answers.
So far, this is what I have.
if(sum(A25_A25A4.NAOK, A25_A25A5.NAOK, A25_A25A6.NAOK, A25_A25A7.NAOK, A25_A25A8.NAOK, A25_A25A9.NAOK < 13), display, hide)
My goal is to display only one bit of text according to a specific sum (from only a few sub-questions of a previous question). The sum function seems to work like this, but I can't understand how to get the If function to work. Do I lack brackets or a specific expression? I have been looking over the forum and haven't been able to find what I needed. The error message tells me an IF equation should be: IF(test, result_if_true, result_if_false).
Writing "display", or "display_if_false" doesn't work.
Thank you in advance for your help!
So far, this is what I have.
if(sum(A25_A25A4.NAOK, A25_A25A5.NAOK, A25_A25A6.NAOK, A25_A25A7.NAOK, A25_A25A8.NAOK, A25_A25A9.NAOK < 13), display, hide)
My goal is to display only one bit of text according to a specific sum (from only a few sub-questions of a previous question). The sum function seems to work like this, but I can't understand how to get the If function to work. Do I lack brackets or a specific expression? I have been looking over the forum and haven't been able to find what I needed. The error message tells me an IF equation should be: IF(test, result_if_true, result_if_false).
Writing "display", or "display_if_false" doesn't work.
Thank you in advance for your help!
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11655
- Thank you received: 2740
5 years 8 months ago #172616
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic IF equation to display specific feedback over the answers
Limesurvey should show you on the question page if a equation is wrong. Looking at yours I think you have set one ")" wrong in your equation.
To find errors it is always good to break a more complicated equation down into bits, to identify where your problem lies.
here is how IF works:
IF(test, result_if_true, result_if_false)
test: in your case the sum and checking if it is smaller than 13. I think here is one of your mistakes. You need to have the sum in brackets and then check for this sum if it is smaller than 13, eg.
You have to close the bracket of sum before you can check "<13".
result_if_true: here you put what you want to happen if your check if the sum is smaller than 13 is true, for example display a specific text.
result_if_true: here you put what you want to happen if the test is not true.
This should work:
To find errors it is always good to break a more complicated equation down into bits, to identify where your problem lies.
here is how IF works:
IF(test, result_if_true, result_if_false)
test: in your case the sum and checking if it is smaller than 13. I think here is one of your mistakes. You need to have the sum in brackets and then check for this sum if it is smaller than 13, eg.
Code:
sum(A25_A25A4.NAOK, A25_A25A5.NAOK, A25_A25A6.NAOK, A25_A25A7.NAOK, A25_A25A8.NAOK, A25_A25A9.NAOK) < 13
You have to close the bracket of sum before you can check "<13".
result_if_true: here you put what you want to happen if your check if the sum is smaller than 13 is true, for example display a specific text.
result_if_true: here you put what you want to happen if the test is not true.
This should work:
Code:
{if(sum(A25_A25A4.NAOK, A25_A25A5.NAOK, A25_A25A6.NAOK, A25_A25A7.NAOK, A25_A25A8.NAOK, A25_A25A9.NAOK) < 13, "This is the text that should be displayed if the sume is < 13", "this is the text that should be displayed if the sum is 13 or more")}
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The following user(s) said Thank You: Emma_F
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
5 years 8 months ago #172619
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic IF equation to display specific feedback over the answers
If using this in the relevance equation of a question (or group), you don't need to use the IF() statement. I would simply be:
If this returns true, the question is shown, if false, the question is hidden.
Code:
sum(A25_A25A4.NAOK, A25_A25A5.NAOK, A25_A25A6.NAOK, A25_A25A7.NAOK, A25_A25A8.NAOK, A25_A25A9.NAOK) < 13
If this returns true, the question is shown, if false, the question is hidden.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Emma_F
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
5 years 8 months ago #172622
by Emma_F
Replied by Emma_F on topic IF equation to display specific feedback over the answers
I'd like to thank you for the help, it's finally working!
The topic has been locked.
- Emma_F
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
5 years 8 months ago #172779
by Emma_F
Replied by Emma_F on topic IF equation to display specific feedback over the answers
Another question on the same subject, as long as the sum I'm working on simply has to be higher than another number, it seems to work, but I have difficulties hiding the text that appears when the sum is between two numbers.
I feel silly, but how should I write the expression for the sum to be recognized?
sum(question.naok,...) <10 >15
I've tried the sum and count function and I've tried locating a similar case, but I can't seem to find the correct way to do it.
Thank you in advance for your time!
I feel silly, but how should I write the expression for the sum to be recognized?
sum(question.naok,...) <10 >15
I've tried the sum and count function and I've tried locating a similar case, but I can't seem to find the correct way to do it.
Thank you in advance for your time!
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11655
- Thank you received: 2740
5 years 8 months ago - 5 years 8 months ago #172780
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic IF equation to display specific feedback over the answers
There are different approaches to this, depending on what you are trying to do.
You could have nested if clauses, e.g.
So you see that we have 2 if statements. The second one is nested within the first one for the "else" part. So if the first test is not true, it will run through the second test.
Or you can split it up into different if statements:
Or you could use OR for your test.
I haven't tested this one, but it should work. If it is wrong, Tpartner probably will come with the correct version soon.
You could have nested if clauses, e.g.
Code:
if(sum(...) < 10; "This sum is smaller than 10"; if(sum(...) > 15; "This sum is bigger than 15"; "This sum is between 10 and 15"))
So you see that we have 2 if statements. The second one is nested within the first one for the "else" part. So if the first test is not true, it will run through the second test.
Or you can split it up into different if statements:
Code:
if(sum(...) < 10; "This sum is smaller than 10"; "") --> This will only write a text if the test is true. Else it will return an empty string. if(sum(...) > 15; "This sum is bigger than 15"; "")
Or you could use OR for your test.
Code:
if(sum(...) < 10 OR > 15; "This sum is either smaller than 10 or bigger than 15"; "This sum is between 10 and 15").
I haven't tested this one, but it should work. If it is wrong, Tpartner probably will come with the correct version soon.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Last edit: 5 years 8 months ago by holch.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
5 years 8 months ago - 5 years 8 months ago #172781
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic IF equation to display specific feedback over the answers
Assuming you are trying to hide/show a question (not tailor text)...
This will only show the question if the sum() function returns less than 10 or greater than 15.
Code:
sum(question.naok,...) <10 OR sum(question.naok,...) >15
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 8 months ago by tpartner.
The topic has been locked.
- Emma_F
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
5 years 8 months ago #172783
by Emma_F
Replied by Emma_F on topic IF equation to display specific feedback over the answers
Thank you very much.
I'm only trying to display text, and using two sums and the function AND is doing the trick, I just needed to figure out the need of writing two separate sums.
sum(A19_A19A.NAOK,...) >= "10" AND sum(A19_A19A.NAOK,...) <= "15"
makes this work perfectly. Thank you both for answering so quickly!
I'm only trying to display text, and using two sums and the function AND is doing the trick, I just needed to figure out the need of writing two separate sums.
sum(A19_A19A.NAOK,...) >= "10" AND sum(A19_A19A.NAOK,...) <= "15"
makes this work perfectly. Thank you both for answering so quickly!
The topic has been locked.
- Emma_F
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
5 years 8 months ago #172845
by Emma_F
Replied by Emma_F on topic IF equation to display specific feedback over the answers
Once again I'm faced with a dilemma for this equation.
I have three different texts I want to display in the following scenarios:
display text #1 ---> sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) < 11
display text #2---> sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) > 10 or sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) < 15
display text #3 ---> sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) > 14
These equations work separately if there's only one blurp of text involved, but the first equation overrides everything. What I obtain with various different tries is either the first text appearing everywhere (in the case I use "AND" in the second equation) or the first and second text appearing even if I face scenario 2 or 3. I'm pretty certain these equations are exclusive and I'm at my wits ends with this problem.
I join the file with these questions, you can ignore question A22.
Thank you in advance for your help.
I have three different texts I want to display in the following scenarios:
display text #1 ---> sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) < 11
display text #2---> sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) > 10 or sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) < 15
display text #3 ---> sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) > 14
These equations work separately if there's only one blurp of text involved, but the first equation overrides everything. What I obtain with various different tries is either the first text appearing everywhere (in the case I use "AND" in the second equation) or the first and second text appearing even if I face scenario 2 or 3. I'm pretty certain these equations are exclusive and I'm at my wits ends with this problem.
I join the file with these questions, you can ignore question A22.
Thank you in advance for your help.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
5 years 8 months ago - 5 years 8 months ago #172853
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic IF equation to display specific feedback over the answers
You need to use nested IF() statements. An IF() statement works as follows:
Now, you can replace the returned result if condition != true with another IF() statement, effectively creating an ELSE IF().
So, in your case, something like this (line-breaks added for clarity):
Code:
if(condition, returned result if condition == true, returned result if condition != true)
Now, you can replace the returned result if condition != true with another IF() statement, effectively creating an ELSE IF().
So, in your case, something like this (line-breaks added for clarity):
Code:
{if(sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) < 11, 'Text if sum less than 11', if(sum(A19_A19A.NAOK, A19_A19B.NAOK, A19_A19C.NAOK, A19_A19D.NAOK, A19_A19E.NAOK) < 15, 'Text if sum less than 15', 'Text if neither condition is true'))}
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 8 months ago by tpartner.
The topic has been locked.