#56 — Get The Same Rows from A Table

#56 — Get The Same Rows from A Table

Problem description & analysis:

The Excel table below has 4 columns. If we regard columns from the 2nd to the 4th as a whole, there are duplicates, as shown below:

ABCD
1#ProductNon ConfDate
21AppleWorms4-Mar-24
33AppleWorms4-Mar-24
42PearWorms4-Mar-24
57PearWorms5-Mar-24
611PearWorms6-Mar-24
710OrangeWorms6-Mar-24
812OrangeWorms6-Mar-24
99AppleRotten6-Mar-24
1013AppleRotten7-Mar-24
114PearRotten4-Mar-24
125OrangeRotten5-Mar-24
136OrangeRotten5-Mar-24
148OrangeRotten6-Mar-24
1514OrangeRotten7-Mar-24

We want to select the same rows to form a new table while retaining the original order.

FGHI
1#ProductNon ConfDate
21AppleWorms4-Mar-24
33AppleWorms4-Mar-24
410OrangeWorms6-Mar-24
512OrangeWorms6-Mar-24
65OrangeRotten5-Mar-24
76OrangeRotten5-Mar-24

Solution:

Enter the following formula in SPL XLL:

=spl("=?.group@u(~.to(2,)).select(~.len()>1).conj()",A2:D15)

As shown in the picture below:

r/esProc_Desktop - Get The Same Rows from A Table

Explanation:

group()function groups the table rows; @ u option enables keeping the original order; ~ is the current member; and to(2,) gets child members of the current member from the 2nd to the last.

This case was originally on StackOverflow. The conventional solution is quite complicated, while the SPL approach is much simpler and more efficient.

Feel free to download esProc Desktop for FREE and experience the efficiency yourself:

SPL download address: esProc Desktop FREE Download

Plugin Installation Method: SPL XLL Installation and Configuration

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

YouTube FREE courses: SPL Programming