Excel Get the Max and Min Values of Each Column in Each Group and Insert Them into Cells Horizontally
Problem description & analysis
In the following table, the 1st column is the grouping column and there are N detail data columns after it.
Z | N_1 | N_2 | Q_12 |
A | 100 | 200 | -100 |
A | 101 | -10 | -200 |
A | 102 | 201 | -104 |
A | 99 | 199 | 300 |
B | 1000 | 1100 | 1300 |
B | 1004 | 1200 | -900 |
C | 2000 | -2100 | 2200 |
C | 1900 | -2090 | -2180 |
The computing task: group rows by the 1st column; insert the maximum value and the minimum value of each column in each group in order into the 2N columns horizontally.
Z | N_1Max | N_1Min | N_2Max | N_2Min | Q_12Max | Q_12Min |
A | 102 | 99 | 201 | -10 | 300 | -200 |
B | 1004 | 1000 | 1200 | 1100 | 1300 | -900 |
C | 2000 | 1900 | -2090 | -2100 | 2200 | -2180 |
Solution
Use SPL XLL to enter the following formula:
=spl("=f=(d=E(?)).fname().m(2:),d.groups(Z;${f.( replace( ""max(*):*Max,min(*):*Min"", ""*"", ~ )).concat@c()})",A1:D9)
Explanation
fname()function gets column names of the table. groups() function groups the rows and perform aggregations. m(:2) gets members from the 2nd to the last, and ~ represents the current members. ${} takes the string as a dynamical code to execute.
esProc Desktop SPL XLL is now FREE to download and feel free to give it a try! http://www.scudata.com/download-Desktop