DEV Community

Cover image for #47 — Sort An EXCEL Table According To Custom Segments
Judith-Excel-Sharing
Judith-Excel-Sharing

Posted on

#47 — Sort An EXCEL Table According To Custom Segments

Problem description & analysis:

An Excel table has three columns:

original table

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:

desired table

Solution:

Use SPL XLL to do this:

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

As shown in the picture below:

reult table with code entered
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.

Top comments (2)

Collapse
 
judith677 profile image
Judith-Excel-Sharing

Feel free to download esProc Desktop and experience the efficiency yourself ⬇️

🔥SPL download address: scudata.com/download-Desktop

💥Plugin Installation Method: c.scudata.com/article/1652061135502

🔥References to other rich Excel operation cases: c.raqsoft.com/article/1651916536524

💥SPL Programming (YouTube FREE courses): youtube.com/playlist?list=PLQeR-Ih...

Collapse
 
judith677 profile image
Judith-Excel-Sharing

Please join our communities to share your Excel tasks:

🪐Discord: discord.gg/PVyKVa2J
🪐Reddit: reddit.com/r/esProc_Desktop/