# Select top 2 from a constant sum

Hi,

I would like to select the top 2 values from a constant sum field.
After that, I would like to use them as column fields in a grid.

+1 vote
Assume your constant sum question is Q1.

We first sort the constant sum items in descending order. We do this via a constructed list. Let's call it "Q1SortedList".
```AddSorted(Q1,0)
```

The next constructed list will extract the highest scored item(s). Remember we may have equal scores, hence the reason we have multiple members stored in this constructed list. Let's call this constructed list Q1High1List. I have assumed you have 10 members in your parent list.
```Begin Unverified Perl

my \$i=1;

for(\$i=1; \$i<=10; \$i++)
{
if (VALUE("Q1_".\$i)==VALUE("Q1_".LISTVALUE("Q1SortedList",1)))
{
}
}

RANDOMIZE();

End Unverified
```

The Q1High1List constructed list will find all items that match the highest numeric score at Q1. We then randomise them.

We now create a similar constructed list to Q1High1List. Let's call it Q1High2List. This will find all items in your constant sum that match the 2nd highest score and then randomise them.

Note: the highest and 2nd highest scores can be the same. This technique will work fine either way.
```Begin Unverified Perl

my \$i=1;

for(\$i=1; \$i<=10; \$i++)
{
if (VALUE("Q1_".\$i)==VALUE("Q1_".LISTVALUE("Q1SortedList",2)))
{
}
}

RANDOMIZE();

End Unverified
```

The final constructed list (Q1Top2List) will simply bring together Q1High1List and Q1High2List and clean the list to 2 items as such ...
```ADD(Q1High1List)