Check out the LimeSurvey source code on GitHub!

if statement to display text

More
4 years 8 months ago #82029 by casfan
Hi there,

just discovering how powerful limesurvey really is. However i have come a bit stuck.
I take it the coding/expressions are based on php?

Basically I have 7 questions that i need to add up to make a score and display that score so this works
Your score is {sum(AC1,AC2,AC3,AC4,AC5,AC6,AC7)}
but then i want to display the level they have got depending on the score.
psedo code would be if score >=7 text= low risk if score <=8&&>=15 text increasing risk if score >=19&&<=19 text = Higher risk if score >=20 text=top risk.

I have tried to build it up slowly
{if((sum(AC1,AC2,AC3,AC4,AC5,AC6,AC7))<=7, 'Low Risk')}
but I get a function does not support 2 arguments error and a not a valid expression error.

What am i doing wrong.

Please Log in to join the conversation.

More
4 years 8 months ago - 4 years 8 months ago #82047 by tpartner
This is untested and I'm not sure I have your thresholds correct but try nesting the IF statements:
{if(sum(AC1,AC2,AC3,AC4,AC5,AC6,AC7)<8, 
	'Low risk', 
	if(sum(AC1,AC2,AC3,AC4,AC5,AC6,AC7)<16, 
		'Increasing risk', 
		if(sum(AC1,AC2,AC3,AC4,AC5,AC6,AC7)<20, 'Higher risk', 
			'Top risk'
		)
	)
)}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 4 years 8 months ago by tpartner.

Please Log in to join the conversation.

More
4 years 8 months ago #82068 by Mazi
An IF statement always takes three parameters:
(IF(<condition>,<text_if_true>,<text_if_false>)

This means that you can also have multiple IF conditions nested which is basically like
IF...
ELSEIF...
ELSEIF...
ELSE...

like Tony has shown above.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form