Excel 分组并将某列合并成串

例题描述和简单分析

有 Excel 数据如下所示:

Session

FirstName

LastName

Email

Address

1

Bob

Smith

bob@1.com

Main Street

2

Bob

Smith

bob@1.com

Main Street

4

Bob

Smith

bob@1.com

Main Street

1

Frank

Jones

Frank@2.com

2nd Street

2

Frank

Jones

Frank@2.com

2nd Street

3

Frank

Jones

Frank@2.com

2nd Street

4

Frank

Jones

Frank@2.com

2nd Street

1

Henry

Andrews

henry@3.com

3rd Street

2

Henry

Andrews

henry@3.com

3rd Street

数据按每个人分组后,将Session 列用逗号分隔拼成串,结果如下所示:

Email

FirstName

LastName

Address

Session

Frank@2.com

Frank

Jones

2nd Street

1,2,3,4

bob@1.com

Bob

Smith

Main Street

1,2,4

henry@3.com

Henry

Andrews

3rd Street

1,2

解法及简要说明

Excel 中加载插件SPL XLL

在空白格输入公式:

=spl("=E(?).group(Email;FirstName,LastName,Address,~.(int(Session)).concat@c():Session)",A1:E10)

如图:

..

返回结果:

..

简要说明: Email 分组,保留除 Session 外的列,Session 列变为用逗号分隔拼成的串。

问答搜集

https://stackoverflow.com/questions/63623624/merge-excel-rows-based-on-single-field