Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
puttemans
Specialist
Specialist

Select top/bottom 5 rows in script depending on variable


Hi all,

I have a file containing thousands of records that can be ordered following a given '% Key to MOAR' (KtM). Per individual KtM, there are still possibly hundreds of records/lines possible.

I would like to cleanup the original file, and make sure that I end up per KtM with a maximum of 5 records/lines, based upon another variable in the set I created, being UniqueKey. Only the 5 lines that have the lowest(fastest) travel time should be selected per KtM. This is the first value in the UniqueKey variable. (notice in the example I need the UniqueKey measure for the top 5, as there is more than 1 train running in the same time between the selected KtM) I managed to create a variable that indicates how many lines per KtM need to be selected, as not all KtM have 5 lines (some have less, and they should then all be taken into account). The Traveltime variable is changing for every KtM, so working with a fixed number is impossible.

Could anyone show me possible routes to a solution?

Thank you

1 Solution

Accepted Solutions
Anonymous
Not applicable

Hello Johan,

The simplest would be to

1 - Order your by KtM, by Travel Time ascending to obtain the appropriate sequence

2 - tag your routes with an index that restarts for every KtM

3 - store the table

4 - load the table for all indices that are < = 5

Hope this helps,

Antoine

View solution in original post

2 Replies
Anonymous
Not applicable

Hello Johan,

The simplest would be to

1 - Order your by KtM, by Travel Time ascending to obtain the appropriate sequence

2 - tag your routes with an index that restarts for every KtM

3 - store the table

4 - load the table for all indices that are < = 5

Hope this helps,

Antoine

puttemans
Specialist
Specialist
Author

Hi Antoine,

Thank you for the help. You made me round that hurdle already , some more challenges to go...