Welcome to the LimeSurvey Community Forum

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

Rank Array Totals & Provide Description by Top Ranked

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago - 8 years 11 months ago #120272 by tpartner

But I still want to know how to rank the results of the 4 arrays & deliver a different text output depending on the highest storing section.


Assumptions:
- 4 Arrays with question codes q1, q2, q3 and q4
- You do not expect any of the array assessment totals to equal another array assessment total

This will give you the "total assessment value" for an array, question code q1:
Code:
{sum(that.q1.value)}

So, then you could create a new "Equation" type question (let's call it "maxVal") with the following equation. This will give the highest "total assessment value".
Code:
{max(sum(that.q1.value), sum(that.q2.value), sum(that.q3.value), sum(that.q4.value))}

Then you can use nested IFs to display variable text depending on which array matches the highest "total assessment value" (line-breaks inserted for clarity):
Code:
{if(q1 == maxVal, 'Text if q1 highest', 
  if(q2 == maxVal, 'Text if q2 highest', 
    if(q3 == maxVal, 'Text if q3 highest', 
      if(q4 == maxVal, 'Text if q4 highest', 
        '' 
))))}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 11 months ago by tpartner.
The topic has been locked.
  • ccapra
  • ccapra's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 11 months ago #120354 by ccapra
Thanks! That all works beautifully!

So now, if there are two max scores, is there a way to give text for both? Like 'you are equally suited to Q1 and Q4' then 'text if q1' and 'text if q2'?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #120359 by tpartner
Well, there may be a more elegant way but you could simply extend the nested IFs:
Code:
{if(q1 == maxVal, 'Text if q1 highest', 
  if(q2 == maxVal, 'Text if q2 highest', 
    if(q3 == maxVal, 'Text if q3 highest', 
      if(q4 == maxVal, 'Text if q4 highest', 
        if(q1 == maxVal AND q2 == maxVal, 'You are equally suited to Q1 and Q2', 
          if(q1 == maxVal AND q3 == maxVal, 'You are equally suited to Q1 and Q3', 
            if(q1 == maxVal AND q4 == maxVal, 'You are equally suited to Q1 and Q4', 
              if(q2 == maxVal AND q3 == maxVal, 'You are equally suited to Q2 and Q3', 
                if(q2 == maxVal AND q4 == maxVal, 'You are equally suited to Q2 and Q4', 
                  if(q3 == maxVal AND q4 == maxVal, 'You are equally suited to Q3 and Q4', 
                    ''
))))))))))}

Or, perhaps several of those nested statements?


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose