Concatenate column values and perform grouping & aggregation
In the table below, the 1st column is person’s name, and the multiple columns after it are items they purchased. There are people who sometimes buy multiple same items in one purchase and who place multiple orders at different times.
A |
B |
C |
D |
|
1 |
John |
Apple |
Apple |
Orange |
2 |
Paul |
Grape |
||
3 |
John |
Pear |
||
4 |
Steve |
Lychee |
Grape |
|
5 |
Jessica |
Apple |
We need to rearrange the table into a crosstab, where the column headers are items and the row headers are people’s names, as shown below:
E |
F |
G |
H |
I |
J |
|
1 |
Name |
Apple |
Orange |
Pear |
Grape |
Lychee |
2 |
Jessica |
1 |
||||
3 |
John |
2 |
1 |
1 |
||
4 |
Paul |
1 |
||||
5 |
Steve |
1 |
1 |
Use SPL XLL to do this:
=spl("=?.groupc@r(~1;~.m(2:);1).pivot@s(~1:Name; ~2,count(~2))",A1:D5)
groupc@r groups members of a sequence by a specified number and transposes columns to rows; ~1 represents the 1st child member of the current member, and ~.m(2:) gets child members of the current member from the 2nd to the last. pivot@s transposes rows to columns and performs aggregation on each group of data.
Source:https://www.reddit.com/r/excel/comments/1ctnd42/trying_to_find_the_total_number_of_times_a_word/
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_Desktop/
SPL Learning Material 👉 https://c.scudata.com
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProcDesktop
Linkedin Group 👉 https://www.linkedin.com/groups/14419406/