Concatenate Column Values and Perform Grouping & Aggregation

Problem description & analysis:

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 a…


This content originally appeared on DEV Community and was authored by Judith-Excel-Sharing

Problem description & analysis:

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.

original table

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:

desired table

Solution:

Use SPL XLL to do this:

=spl("=?.groupc@r(~1;~.m(2:);1).pivot@s(~1:Name; ~2,count(~2))",A1:D5)

As shown in the picture below:

desired result table with code entered

Explanation:

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.


This content originally appeared on DEV Community and was authored by Judith-Excel-Sharing


Print Share Comment Cite Upload Translate Updates
APA

Judith-Excel-Sharing | Sciencx (2024-07-08T02:16:29+00:00) Concatenate Column Values and Perform Grouping & Aggregation. Retrieved from https://www.scien.cx/2024/07/08/concatenate-column-values-and-perform-grouping-aggregation/

MLA
" » Concatenate Column Values and Perform Grouping & Aggregation." Judith-Excel-Sharing | Sciencx - Monday July 8, 2024, https://www.scien.cx/2024/07/08/concatenate-column-values-and-perform-grouping-aggregation/
HARVARD
Judith-Excel-Sharing | Sciencx Monday July 8, 2024 » Concatenate Column Values and Perform Grouping & Aggregation., viewed ,<https://www.scien.cx/2024/07/08/concatenate-column-values-and-perform-grouping-aggregation/>
VANCOUVER
Judith-Excel-Sharing | Sciencx - » Concatenate Column Values and Perform Grouping & Aggregation. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/08/concatenate-column-values-and-perform-grouping-aggregation/
CHICAGO
" » Concatenate Column Values and Perform Grouping & Aggregation." Judith-Excel-Sharing | Sciencx - Accessed . https://www.scien.cx/2024/07/08/concatenate-column-values-and-perform-grouping-aggregation/
IEEE
" » Concatenate Column Values and Perform Grouping & Aggregation." Judith-Excel-Sharing | Sciencx [Online]. Available: https://www.scien.cx/2024/07/08/concatenate-column-values-and-perform-grouping-aggregation/. [Accessed: ]
rf:citation
» Concatenate Column Values and Perform Grouping & Aggregation | Judith-Excel-Sharing | Sciencx | https://www.scien.cx/2024/07/08/concatenate-column-values-and-perform-grouping-aggregation/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.