Have an idea?

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

Show Question based on Least Fill Quota

I have Q1 with 27 brands
Q3 have following conditions

1. Q3 IS A SERIES OF QUESTIONS, ONE QUESTION PER BRAND –
2. IF 7 OR FEWER BRANDS SELECTED IN Q1, SHOW EACH OF THEM IN Q3 FOLLOW-UPS
3. IF >7 BRANDS SELECTED, USE SOME SORT OF LEAST FILL QUOTA (I.E., SEND RESPONDENT TO THE BRANDS WITH THE LOWEST QUOTA COUNT FIRST). IF QUOTAS ARE EQUAL, RANDOMLY CHOOSE
4. SHOW A MAXIMUM OF 7 IN Q3 FOLLOW-UPS

I have created 27 quotas with the name of Q3QP1 to Q3QP27
and added 2 constructed list

List 1
-------

AIC(Q1)


List 2
-------
Begin Unverified Perl

if (LISTLENGTH("Q3List")<=7)
{ADD("Q3List")}

else
{
    
my $i=0;
my $small=0;
my $pos1=0;
my $pos2=0;
my $pos3=0;
my $pos4=0;
my $pos5=0;
my $pos6=0;
my $pos7=0;

    
    
$small=QUOTACELLCOMPLETES("Q3QP1", 1);
for($i=1;$i<=27;$i++)
{
        if((QUOTACELLCOMPLETES("Q3QP" . $i, 1) <= $small) && LISTHASPARENTMEMBER("Q3List", $i)==1)
        {
            $pos1=$i;
            $small=QUOTACELLCOMPLETES("Q3QP" . $i, 1);
        }
}

$small=QUOTACELLCOMPLETES("Q3QP1", 1);
for($i=1;$i<=27;$i++)
{
        if($pos1!=$i)
        {
        if((QUOTACELLCOMPLETES("Q3QP" . $i, 1) <= $small) && LISTHASPARENTMEMBER("Q3List", $i)==1)
        {
            $pos2=$i;
            $small=QUOTACELLCOMPLETES("Q3QP" . $i, 1);
        }
        }
}

$small=QUOTACELLCOMPLETES("Q3QP1", 1);
for($i=1;$i<=27;$i++)
{
        if($pos1!=$i && $pos2!=$i)
        {
        if((QUOTACELLCOMPLETES("Q3QP" . $i, 1) <= $small) && LISTHASPARENTMEMBER("Q3List", $i)==1)
        {
            $pos3=$i;
            $small=QUOTACELLCOMPLETES("Q3QP" . $i, 1);
        }
        }
}

$small=QUOTACELLCOMPLETES("Q3QP1", 1);
for($i=1;$i<=27;$i++)
{
        if($pos1!=$i && $pos2!=$i && $pos3!=$i)
        {
        if((QUOTACELLCOMPLETES("Q3QP" . $i, 1) <= $small) && LISTHASPARENTMEMBER("Q3List", $i)==1)
        {
            $pos4=$i;
            $small=QUOTACELLCOMPLETES("Q3QP" . $i, 1);
        }
        }
}

$small=QUOTACELLCOMPLETES("Q3QP1", 1);
for($i=1;$i<=27;$i++)
{
        if($pos1!=$i && $pos2!=$i && $pos3!=$i && $pos4!=$i)
        {
        if((QUOTACELLCOMPLETES("Q3QP" . $i, 1) <= $small) && LISTHASPARENTMEMBER("Q3List", $i)==1)
        {
            $pos5=$i;
            $small=QUOTACELLCOMPLETES("Q3QP" . $i, 1);
        }
        }
}


$small=QUOTACELLCOMPLETES("Q3QP1", 1);
for($i=1;$i<=27;$i++)
{
        if($pos1!=$i && $pos2!=$i && $pos3!=$i && $pos4!=$i && $pos5!=$i)
        {
        if((QUOTACELLCOMPLETES("Q3QP" . $i, 1) <= $small) && LISTHASPARENTMEMBER("Q3List", $i)==1)
        {
            $pos6=$i;
            $small=QUOTACELLCOMPLETES("Q3QP" . $i, 1);
        }
        }
}

$small=QUOTACELLCOMPLETES("Q3QP1", 1);
for($i=1;$i<=27;$i++)
{
        if($pos1!=$i && $pos2!=$i && $pos3!=$i && $pos4!=$i && $pos5!=$i && $pos6!=$i)
        {
        if((QUOTACELLCOMPLETES("Q3QP" . $i, 1) <= $small) && LISTHASPARENTMEMBER("Q3List", $i)==1)
        {
            $pos7=$i;
            $small=QUOTACELLCOMPLETES("Q3QP" . $i, 1);
        }
        }
}
    
ADD("Q3List", $pos1);
ADD("Q3List", $pos2);
ADD("Q3List", $pos3);
ADD("Q3List", $pos4);
ADD("Q3List", $pos5);
ADD("Q3List", $pos6);
ADD("Q3List", $pos7);
        
}

End Unverified



but it doesn't work, it shows only 2 or 3 brands if I selected more than 7 brands in Q1.

Please help me to achieve this logic.

Thanks
asked May 19, 2021 by Abdul Bronze (3,220 points)

1 Answer

0 votes
We can use "Multi-Select Quota" from the Community Question Library for this.

https://sawtoothsoftware.com/resources/question-library/multi-select-quota

It may take a minute to get it setup, but I can help with any confusion that comes with using it.  Exporting cells, editing in Excel or a similar program, then importing back into Lighthouse Studio may be fastest.  For your case, you'll want to use seven quota questions (and seven pass-in fields as helpers) - because that's the maximum number of selections any respondent can take.  Each quota will need 27 cells - the total number of items from the initial brand question.  The qualification logic of the cells should continue the pattern that exists when you first add the questions to your survey.

The settings you'll want to use in the very first cell should look like this:

# ****************************************************************************************************
# Parameters
# ****************************************************************************************************
my $quotaBaseName = 'MultiSelectQuota';
my $passInBaseName = 'MultiSelectQuotaHelper';

my $checks = NUMCHECKED('Q3');
my $numberOfQuotas = 7; # the number of quota questions, and the maximum number of choices to make for any respondent
my $numberOfQuotaCells = 27; # the number of cells per quota question, and the number of options to choose from
my $numberOfChoices = $checks > 7 ? 7 : $checks; # the number of choices to make for this respondent, between 0 and $numberOfQuotas

my $membershipOrder = 2; # 1 - sequentially, 2 - least fill, 3 - randomize

my %qualifications = ( # whether the current respondent should qualify for a given cell; by default, all cells are qualified
    1 => sub { return GETVALUE('Q3_1'); },
    2 => sub { return GETVALUE('Q3_2'); },
    3 => sub { return GETVALUE('Q3_3'); },
    4 => sub { return GETVALUE('Q3_4'); },
    5 => sub { return GETVALUE('Q3_5'); },
    6 => sub { return GETVALUE('Q3_6'); },
    7 => sub { return GETVALUE('Q3_7'); },
    8 => sub { return GETVALUE('Q3_8'); },
    9 => sub { return GETVALUE('Q3_9'); },
    10 => sub { return GETVALUE('Q3_10'); },
    11 => sub { return GETVALUE('Q3_11'); },
    12 => sub { return GETVALUE('Q3_12'); },
    13 => sub { return GETVALUE('Q3_13'); },
    14 => sub { return GETVALUE('Q3_14'); },
    15 => sub { return GETVALUE('Q3_15'); },
    16 => sub { return GETVALUE('Q3_16'); },
    17 => sub { return GETVALUE('Q3_17'); },
    18 => sub { return GETVALUE('Q3_18'); },
    19 => sub { return GETVALUE('Q3_19'); },
    20 => sub { return GETVALUE('Q3_20'); },
    21 => sub { return GETVALUE('Q3_21'); },
    22 => sub { return GETVALUE('Q3_22'); },
    23 => sub { return GETVALUE('Q3_23'); },
    24 => sub { return GETVALUE('Q3_24'); },
    25 => sub { return GETVALUE('Q3_25'); },
    26 => sub { return GETVALUE('Q3_26'); },
    27 => sub { return GETVALUE('Q3_27'); }
);


"MultiSelectQuota" and "MultiSelectQuotaHelper" being replaced with the base names of the quotas and pass-in fields, per the regular instructions.

The cells respondents are put into are your 1-7 selected brands.  You could use a constructed list like this if you want:

Add(list1, MultiSelectQuota1)
Add(list1, MultiSelectQuota2)
Add(list1, MultiSelectQuota3)
answered May 19, 2021 by Zachary Platinum Sawtooth Software, Inc. (201,975 points)
Adaption to the new version of the Multi-Select Quota
...