#47 - Sort An EXCEL Table According To Custom Segments

#47 - Sort An EXCEL Table According To Custom Segments

Problem description & analysis:

An Excel table has three columns:

ABC
1A1B151
2A2B2721
3A3B3382
4A4B49
5A5B573
6A6B6577
7A7B791
8A13B13150
9A14B1449
10A17B17702
11A18B18705
12A34B3433
13A35B35409
14A36B36579
15A37B3710

We want to sort rows of the table according to different segments of the 3rd column in ascending order. The 1st segment: the 3rd column value≤50; the 2nd segment: 700 < the 3rd column value < 720; the 3rd segment: the other cases (50 < the 3rd column value < 700 or the 3rd column value > 720). Below is the expected result:

EFG
1A4B49
2A37B3710
3A34B3433
4A14B1449
5A17B17702
6A18B18705
7A1B151
8A5B573
9A7B791
10A13B13150
11A3B3382
12A35B35409
13A6B6577
14A36B36579
15A2B2721

Solution:

Use SPL XLL to do this:

=spl("=?.enum@n([$[?<=50],$[?>=701 && ?<=720]],~3).conj(~.sort(~3))",A1:C15)

As shown in the picture below:

Picture1png

Explanation:

enum()function performs enumerated grouping according to the value of the specified string expression; $[] represents a string; @ n option enables putting members that do not meet the enumerated conditions in one and separate group. ~ is the current member of a sequence, and ~3 is the 3rd member of a sequence.

Please feel free to download esProc Desktop for FREE ⬇️

SPL download address: esProc Desktop Download

Plugin Installation Method: SPL XLL Installation and Configuration

References to other rich Excel operation cases: Desktop and Excel Data Processing Cases

SPL Programming (YouTube FREE courses): https://www.youtube.com/playlist?list=PLQeR-IhHo7qNCw6o7PW8YfHvRx8pgzZso