DEV Community

Cover image for Concatenate Column Values and Perform Grouping & Aggregation
Judith-Data-Processing-Hacks
Judith-Data-Processing-Hacks

Posted on

2 1 1 1 1

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 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)
Enter fullscreen mode Exit fullscreen mode

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.

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

Top comments (2)

Collapse
 
judith677 profile image
Judith-Data-Processing-Hacks

You can also visit our Discord and Reddit communities to get more solutions to difficult Excel tasks! The experts there are generous enough to offer a hands! 🙌🏻 discord.gg/hgbKEvJ4
🙌🏻 reddit.com/r/esProc_Desktop/

Collapse
 
judith677 profile image
Judith-Data-Processing-Hacks

For more SPL XLL related information:

SPL download address: scudata.com/download-Desktop

Plugin Installation Method: c.scudata.com/article/1652061135502

References to other rich Excel operation cases: c.raqsoft.com/article/1651916536524

SPL Programming (YouTube FREE courses): youtube.com/playlist?list=PLQeR-Ih...

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay