分组汇总时保留不变列

Excel表格的ID列是分类,Value1Value2是数值,ID相同时Descr 1Descr 2保持不变。


A B C D E
1 ID Value 1 Value 2 Descr 1 Descr 2
2 11 2.5 1.8 a x1
3 11 2.3 1.1 a x1
4 11 1.9 1.6 a x1
5 12 3.7 3.5 b x2
6 12 3.9 1.5 b x2
7 13 2.5 0.2 c x3
8 13 2.6 4.1 c x3
9 13 2 4.8 c x3
10 13 2.7 1.8 c x3

要求:低版本的Excel(不支持groupby函数),按ID分组,对Value1Value2求和,保留Descr 1Descr 2


G H I J K
1 ID Value 1 Value 2 Descr 1 Descr 2
2 11 6.7 4.5 a x1
3 12 7.6 5 b x2
4 13 9.8 10.9 c x3

使用 SPL XLL

=spl("=E(?).groups(ID;sum('Value 1'):'Value 1',sum('Value 2'):'Value 2','Descr 1','Descr 2')",A1:E10)

Picture1png

函数 E 将片区转为表格,groups 对表格分组汇总,计算出的新列可以用冒号改名。

来源:https://stackoverflow.com/questions/78155495/excel-sum-max-min-multiple-rows-insert-new-row-and-delete-added-rows