#38 - Group Columns of An Excel Table And Perform Aggregation

#38 - Group Columns of An Excel Table And Perform Aggregation

Problem description & analysis:

In the Excel table below, there are multiple duplicate columns.

ABCDEFGH
AlphaAlphaBetaBetaAlphaDeltaBeta
1A0.560.10.550.740.380.020.44
2B0.060.320.220.550.90.70.38
3C0.160.080.630.90.70.780.2
4D0.80.920.030.570.480.520.28
5E0.470.210.810.40.680.80.13
6F0.390.190.760.880.690.810.81

We need to group the table by columns and sum values in each group.

ABCD
10AlphaBetaDelta
11A1.041.730.02
12B1.281.150.7
13C0.941.730.78
14D2.20.880.52
15E1.361.340.8
16F1.272.450.81

Solution:

Use SPL XLL to get this done:

=spl("=E@2bp(E@bp(?).groups(#1;${(?.len()-1).(eval@s($[sum(#?)],#+1)).concat@c()}))",B1:H7)

As shown in the picture below:

Picture1png

Explanation:

E()function converts an Excel table to a two-layer sequence; @ p option enables a transposition, @ b means not converting the titles, and @ 2 represents a two-layer sequence. groups() performs grouping and sum; ${} treats a string as an expression to execute. eval@s() loops each string in a sequence to replace them and takes them as an expression to execute. concat@c concatenates members of the sequence using the comma.

Please feel free to download SPL XLL and boost your Excel productivity ⬇️

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