DEV Community

Cover image for #122 — Put Every N Members in a Group
Judith-Data-Processing-Hacks
Judith-Data-Processing-Hacks

Posted on

2 1 1 1 1

#122 — Put Every N Members in a Group

Problem description & analysis:

Here below is a data table:

source table

Task: We want to put every 4 rows in order in a group, and calculate the serial number of the group and the sum of the values in the second column of each group.

Solution:

Use SPL XLL and enter the following one-line code:

=spl("=E@b(?1).groups((#-1)\4+1:ID;sum(#2):Total)",A1:B12)
Enter fullscreen mode Exit fullscreen mode

The results are as follows:

result table

To put every 4 rows in a group, we can group by the result of (#-1)\4+1, that is, subtract 1 from row number # to get the difference, divide the difference by 4 to get the quotient, and add 1 to the quotient. After grouping, we can count the sum of the values in the second column of each group.


Download esProc Desktop for FREE and work smarter with your data using SPL XLL!! 🚀✨⬇️

✨SPL download address: esProc Desktop FREE Download

✨Plugin Installation Method: SPL XLL Installation and Configuration

✨References to other rich Excel operation cases: Desktop and Excel Data Processing Cases

✨YouTube FREE courses: SPL Programming

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

Top comments (1)

Collapse
 
judith677 profile image
Judith-Data-Processing-Hacks

Wishing you peace, joy, and productive holidays! 🎄✨🌟
And feel free to join the communities:

⭐️Discord
⭐️Reddit

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more