Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Find highest values in a grid question and add the items to a constructed list

My title is slightly incomplete.

I have grid question asking respondents to rate some items from 1 to 7. The rows come from an earlier constant sum question.

What I'm trying to do is add the highest ranked item to a new constructed list, but also add any items that have the same rank value. So if a respondent selected the highest ranked item as a 6, but also ranked another item as a 6, both items would be added to the new constructed list.

I feel  like this is easier than I have been making it, but unverified perl game has gotten rusty.

Any help would be greatly appreciated.
asked Aug 25, 2021 by Daniel F. Bronze (800 points)

1 Answer

+2 votes
 
Best answer
Daniel, we can do this with 2 constructed lists.

Other solutions maybe more efficient, but this works nicely and isn't much work to put together.

My assumptions are as follows ...

Grid question name: QX
Rows: 5 items (saved in parent list QXRowList)
Columns: Scale 1-7 rating

Note: Feel free to change my scripting variables to match yours.

Create constructed list #1. Call it QXRankedList. Insert the following SSI Script ...
AddSorted(QX,0)

This constructed list sorts the items from highest ranked down to lowest ranked.

Create constructed list #2. Call it QXHighestList. Insert the following Perl Script ...
Begin Unverified Perl

 my $i=1;
 my $numitems=LISTLENGTH("QXRowList");

 for($i=1; $i<=$numitems; $i++)
  {
   if (VALUE("QX_r".$i)==VALUE("QX_r".LISTVALUE("QXRankedList",1)))
    {  
     ADD("QXRowList",$i);
    }  
  }

 RANDOMIZE();

End Unverified

This constructed list matches all items ranked the highest from constructed list #1: QXRankedList.

I just gave it a test drive. Worked like a charm.
answered Aug 25, 2021 by Paul Moon Platinum (101,405 points)
selected Aug 25, 2021 by Daniel F.
Note: You can also throw in a RANDOMIZE(); command in QXHighestList to randomise the highest ranked items.
Thank you. Works perfectly.
...