# Taking least filled quota based on selection

I'm trying to fill (roughly) evenly fill a quota with 3 cells. I know how to implement a simple least fill algorithm (e.g., fill cell 1 if cell 1 is <= cell 2 and <= cell 3), but I also want to fill this quota based on a multiple selection question where respondents can indicate whether they belong to group 1/2/3.

I'd like the logic to operate as: respondents fill the quota for which their selection matches when all quota cells are open; if they select multiple groups, they get assigned to the quota cell that is least full; if they select a group or groups whose quota cells are closed, they get assigned to the least full cell remaining. Many thanks!

+1 vote

It's bit tricky, you need to check this in constructed list. Then you need to check constructed list's first item for assigning brand.

I am going to  explain this with detail example.  Let's say we have Q1 question as multiple select question with 3 options and we had set up Quota "Brand". Now we need to add brand from Q1List based on least fill. I am going to create constructed list "AssignBrand"

```Begin Unverified Perl
my \$sum1=99999;
my \$sum2=99999;
my \$sum3=99999;

my @sum_value;
my @sum_min;

if(VALUE('Q1_1')==1 and ISQUOTACELLOPEN('Brand',1) )
{
\$sum1=QUOTACELLCOMPLETES("Brand",1);
}
if(VALUE('Q1_2')==1 and ISQUOTACELLOPEN('Brand',2) )
{
\$sum2=QUOTACELLCOMPLETES("Brand",2);
}
if(VALUE('Q1_3')==1 and ISQUOTACELLOPEN('Brand',3) )
{
\$sum3=QUOTACELLCOMPLETES("Brand",3);
}

\$sum_value[0][0]=\$sum1;
\$sum_value[1][0]=\$sum2;
\$sum_value[2][0]=\$sum3;

\$sum_value[0][1]="1";
\$sum_value[1][1]="2";
\$sum_value[2][1]="3";

@sum_min=sort{\$a->[0]<=>\$b->[0]}@sum_value;