Sorting an Exploration

I have attached a photo of an exploration I run which sorts by several criteria. The data is derived from IBD eTables using a script written by @rocketpower that he shared in the forum. My question is in regard to 2nd sort column where the data is not a number but rather letters such as A+, A, A-, B+, B, B-, etc. As you can see in the photo, "A" comes before "A+", and then "A-". This data is stored as a static variable if that matters. My question specifically is, is there a method that I can use that would sort in a way that "A+" comes BEFORE "A"? I have tried creating an array using conditions such as the following, but it isn't recognized (If you think the entire code is necessary to fully understand the issue let me know and I will be more than happy to post):

CondAplus = "A+" = 1;
CondA = "A" = 2;

Screen Shot 2021-04-17 at 3.38.56 PM

@MCassICT one easy way is to replace the letters A+, A, A- with A, AA, AAA , etc.

3 Likes

You could assign numerical values to those, like this:

list = "A+,A,A-,B+,B,B-,C+,C,C-,D+,D,D-,E+,E,E-";

smr = "E";

for( i = 0; ( item = StrExtract( list, i ) ) != ""; i++ )
{
   if( item == smr )
   {
      numerical_value = i;
      break;
   }
}

and then add numeric column, it will allow you to do sorting.

4 Likes

@MCassICT Remember that if you follow Tomasz's advice and use this additional numerical column for sorting purposes (but maybe you don't want to see it), you can hide it by setting its width to 1 or 0. In both cases the results will be sorted according to your needs even if such column is not visible. When you set its width to 1, you will be able to retrieve this column (and make it visible) using your mouse.

You will find more examples in these threads:

2 Likes

Thank all three of you very much.....I'll give your advice a shot.

I think you can also do Switch/case. But it's long to type it in, but easy to figure out, read and debug.

    switch( SMRGrade )
    {
        case "A+":
            SMRDecimal = 15;
            break;

        case "A":
            SMRDecimal = 14;
            break;

// and so on for all grades
    }
1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.