Have an idea?

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

How to pop-up label question from 6 questions follow condition

Dear All,

Q1 is grid-numeric with 6 rows.
=> Row1 can range 1-100.
=> Row2 can range 1-100.
=> Row3 can range 1-100.
=> Row4 can range 1-100.
=> Row5 can range 1-100.
=> Row6 can range 1-100.

Q2Row1 is select question with 5 score (1|2|3|4|5).
Q3Row2 is select question with 5 score (1|2|3|4|5).
Q4Row3 is select question with 5 score (1|2|3|4|5).
Q5Row4 is select question with 5 score (1|2|3|4|5).
Q6Row5 is select question with 5 score (1|2|3|4|5).
Q7Row6 is select question with 5 score (1|2|3|4|5).

Q8 is Open-End and I want to pop-up label from Q1 by using conditions below:
=> If code 4 or 5 in among Q2Row1 or Q3Row2 or Q4Row3 or Q5Row4 or Q6Row5 or Q7Row6 and top score in Q1. We will pop-up that row label in question.
=> If none code 4 or 5 and display code 3 in among Q2 or Q3 or Q4 or Q5 or Q6 or Q7 and top score in Q1.  We will pop-up that row label in question.
=> If none code 3, 4 and 5 in among Q2 or Q3 or Q4 or Q5 or Q6 or Q7.  We will pop-up the row label base on top score in Q1.

Hope you understand!!!
asked Oct 14, 2019 by Saroeun Bronze (1,945 points)
edited Oct 14, 2019 by Saroeun
How are ties meant to be handled, such as two items with a 100 response in Q1 and a 5 response in their follow-up questions?
Condition for Q1:
=> Score 100 can input only 1 row.
=> Score 1 can input only 1 row.
=> For each of the remaining rows, please input a score between 2 and 99.
=> No 2 rows can be given the same score.

Please help fix this!!!
Sorry, I'm still a little confused.  This is your order, right?

1. If the highest ranking item in Q1 is given a 4 or 5 in the follow-up question, show it in the open-end question.

2. If the highest ranking item in Q1 is given a 3 in the follow-up question, show it in the open-end question.

3. Show the highest ranking item in Q1 in the open-end question.

Doesn't this just boil down to always showing the highest ranked item in the open-end question?  In what situation would the item ranked highest in Q1 not be the item shown in the open-end?
Thanks Zachary, I will give you some example for each conditions in Q8:

I choose 3 questions among 6 from above to make example.

Example 1: (For code 4 or 5)
if code 4 or 5 have answered in Q2Row1 and Q3Row2 and Q5Row4 => we will compare the score Row1, Row2, Row4 in Q1 which one is top and pop-up that row in the open-end.

Example 2: (For code 3 if no code 4 or 5 have answered)
if No code 4 or 5 but code 3 have answered in Q2Row1 and Q3Row2 and Q5Row4 => we will compare the score Row1, Row2, Row4 in Q1 which one is top and pop-up that row in the open-end.

Example 3: (No code 3 or 4 or 5 have answered)
if No code 3 or 4 or 5 have answered => Which one Row in Q1 is biggest and pop-up that row in the open-end.

Hope you understand!!!
Zachary, could you help to fix this?

1 Answer

0 votes
Please try this code:

[% Begin Unverified Perl
my %rows = (
    1 => 'Q2Row1',
    2 => 'Q3Row2',
    3 => 'Q4Row3',
    4 => 'Q5Row4',
    5 => 'Q6Row5',
    6 => 'Q7Row6'
);

my $bestRow = 0;
my $highestQ1Score = 0;
my $highestFollowupScore = 0;

for my $row (keys %rows) {
    my $q1Score = GETVALUE('Q1_r' . $row . '_c1');
    my $followupScore = GETVALUE($rows{$row});
    if ($followupScore <= 2) {
        $followupScore = 1;
    }
    elsif ($followupScore == 3) {
        $followupScore = 2;
    }
    else {
        $followupScore = 3;
    }
    
    if ($followupScore > $highestFollowupScore || ($followupScore == $highestFollowupScore && $q1Score > $highestQ1Score)) {
        $bestRow = $row;
        $highestQ1Score = $q1Score;
        $highestFollowupScore = $followupScore;
    }
}

return LISTLABEL('list1', $bestRow);
End Unverified %]


"list1" must be replaced with the name of the list of six items.
answered Oct 15, 2019 by Zachary Platinum Sawtooth Software, Inc. (144,125 points)
Instead of using a constructed list and ListLabel, try just placing my code where you would have used ListLabel.
Could you explain this script:

if ($followupScore <= 2) {
        $followupScore = 1;
    }
    elsif ($followupScore == 3) {
        $followupScore = 2;
    }
    else {
        $followupScore = 3;
    }

THanks
It recodes the responses to the follow-up questions from a 5-point scale to a 3-point scale: 1 and 2 become 1, 3 becomes 2, and 4 and 5 become 3.  Keeps my code from having to do that "value >= 4 && value <= 5" stuff you did in your constructed list code.
Sorry for inconvenience. To protect confusion,  could you explain your full script:

[% Begin Unverified Perl
my %rows = (
    1 => 'Q2Row1',
    2 => 'Q3Row2',
    3 => 'Q4Row3',
    4 => 'Q5Row4',
    5 => 'Q6Row5',
    6 => 'Q7Row6'
);
 
my $bestRow = 0;
my $highestQ1Score = 0;
my $highestFollowupScore = 0;
 
for my $row (keys %rows) {
    my $q1Score = GETVALUE('Q1_r' . $row . '_c1');
    my $followupScore = GETVALUE($rows{$row});
    if ($followupScore <= 2) {
        $followupScore = 1;
    }
    elsif ($followupScore == 3) {
        $followupScore = 2;
    }
    else {
        $followupScore = 3;
    }
     
    if ($followupScore > $highestFollowupScore || ($followupScore == $highestFollowupScore && $q1Score > $highestQ1Score)) {
        $bestRow = $row;
        $highestQ1Score = $q1Score;
        $highestFollowupScore = $followupScore;
    }
}
 
return LISTLABEL('list1', $bestRow);
End Unverified %]
Lines 2-9 creates a data structure that maps which rows of the first question relate to which followup question.

Lines 11-13 represent whichever item is currently considered best, as well as its response in Q1 and the followup question.  Defaults to a non-existing zeroth item.

Line 15 makes the next part of the code iterate over every row in Q1.

Lines 16-26 get the responses to Q1 and the followup question for the Nth item, recoding the followup response as mentioned earlier.

Line 28 checks whether the Nth item has a higher followup score or higher Q1 score than whichever item is currently considered best.  If it does, lines 29-31 record this item as the new best item.

Then line 35 returns whichever item came out on top.
...