Welcome, Guest
Username: Password: Remember me

TOPIC: if statement to display text

if statement to display text 2 years 5 months ago #82029

  • casfan
  • casfan's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
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.
The administrator has disabled public write access.

Re: if statement to display text 2 years 5 months ago #82047

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4364
  • Thank you received: 827
  • Karma: 381
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 2 years 5 months ago by tpartner.
The administrator has disabled public write access.

Re: if statement to display text 2 years 5 months ago #82068

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5423
  • Thank you received: 307
  • Karma: 252
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)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.272 seconds
Donation Image