Have an idea?

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

Finding higher frequency among loop question

I have 2 questions as detail below:

Q1. Which of these Energy drink brands have you drink in last 3 months? [Multiple answer]
=> This question is "Select question" and there are 15 brands.

Q2. How often do you drink  [Loop from Q1]  in the past 3 months?
Answers list :
a). 8+ times per week
b). 6-7 times per week
c). 3-5 times per week
d.) Less than 3 can/bottle per week

Question:

1. If Q1 answer more than 1 brand, choose the higher frequency (bottle per week) in Q2
2. If the higher frequency is equal, show those brands and then we can select one of them.

How can I do that?
asked Nov 22 by Saroeun Bronze (3,085 points)

1 Answer

0 votes
 
Best answer
Create a constructed list with these instructions:

Begin Unverified Perl
# Settings
my $frequencyQuestion = 'Q2';

# Run
my $parentList = PARENTLISTNAME();
my $bestScore = 999;
for (my $i = 1; $i <= LISTLENGTH($parentList); $i++) {
    my $score = GETVALUE($frequencyQuestion . '.' . $i);
    if ($score) {
        if ($score < $bestScore) {
            REMOVE($parentList);
            $bestScore = $score;
        }
        if ($score == $bestScore) {
            ADD($parentList, $i);
        }
    }
}
End Unverified


"Q2" should be updated with the name of your "times per week" question.

Now, create a radio-type select question Q3 and give it this constructed list.  If a tie exists, respondents will see this question and have to select an item.  If no tie exists, Q3 will automatically skip and select the best item.
answered Nov 22 by Zachary Platinum Sawtooth Software, Inc. (212,950 points)
selected Nov 23 by Saroeun
...