Welcome to the LimeSurvey Community Forum

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

Maximum and Second maximum

  • ernahaka
  • ernahaka's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 months ago - 3 years 3 months ago #210790 by ernahaka
Maximum and Second maximum was created by ernahaka
Hello everone,

I already built the questions of the survey, and i made some calculations (with Joffm's help). Now I have 6 values stored in 6 questions (equation type): totalA, totalB, ...totalE

Here's what i need to do:
- find the 2 highest values among the 6 values: totalA,,,, totalE ; if for example, the highest value is totalB, and the 2nd highest is totalE
- display the text: "Your score is BE"
- display a text according to BE 

Thanks for your kind help!

PS: LS is Version 4.3.15+200907
Last edit: 3 years 3 months ago by ernahaka. Reason: added Limesurvey version
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #210807 by Joffm
Replied by Joffm on topic Maximum and Second maximum
Hm,
maybe it is not the shortest solution, but only with ExpressionScript.
Well, you have six equations with the 6 scores.
Create 4 equations:
1. Calculate the maximum score in equation "totalVal1"
{max(totalA,totalB,totalC,totalD,totalE,totalF)}

2. Store which one it was (in case of equal scores) in equation "totelName1"
{if(totalA==totalVal1,"totalA",if(totalB==totalVal1,"totalB",if(totalC==totalVal1,"totalC",if(totalD==totalVal1,"totalD",if(totalE==totalVal1,"totalE","totalF")))))}

3. Calculate the second score in equation "totelVal2"
{max(if(totalName1!="totalA",totalA,0),if(totalName1!="totalB",totalB,0),if(totalName1!="totalC",totalC,0),if(totalName1!="totalD",totalD,0),if(totalName1!="totalE",totalE,0),if(totalName1!="totalF",totalF,0))}
You see there are only included the values not equal to "totalName1"

4. Store which one it was (in case that it is necessary)
{if(totalA==totalVal2 AND totalName1!="totalA","totalA",if(totalB==totalVal2 AND totalName1!="totalB","totalB",if(totalC==totalVal2 AND totalName1!="totalC","totalC",if(totalD==totalVal2 AND totalName1!="totalD","totalD",if(totalE==totalVal2 AND totalName1!="totalE","totalE","totalF")))))}

Now you have the two values of the two highest scores, "totalVal1" and "totalVal2" and the names of the two highest sections.
If you rename "totalA" to "Ant", "totalB" to "Beaver", "totalC" to "Chinchilla",... or whatever your survey is about, you may display something like
You received the highest score of {totalVal1} points in section {totalName1} and the second highest score of {totalVal2} points in section {totalName2}.
So in total you received {sum(totalVal1,totalVal2)} points.


Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu, lepsid, ernahaka
The topic has been locked.
  • ernahaka
  • ernahaka's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 months ago #210856 by ernahaka
Replied by ernahaka on topic Maximum and Second maximum
hi Joffm, it worked GREAT, one million thanks!
The topic has been locked.
More
3 years 2 months ago #211956 by lepsid
Replied by lepsid on topic Maximum and Second maximum
I also needed the same solution. Thank you so much!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose