DEV Community

Cover image for #126 — Group When Encountering Non-Null Values
Judith-Excel-Sharing
Judith-Excel-Sharing

Posted on

#126 — Group When Encountering Non-Null Values

Problem description & analysis:

We have an annual and monthly water-consumption data table, and the year is filled in only on the left of the first month of each year. Part of the data is shown as below:

source table

Task: Calculate the total water consumption of each year.

Solution:

Use SPL XLL and enter the formula in cell D1:

=spl("=E(?1).derive(:TotalWater).group@i(Year!=null).run(~(1).TotalWater=~.sum(Water)).conj().new(TotalWater)",A1:C20)
Enter fullscreen mode Exit fullscreen mode

The results are as follows:

result table

When meeting a non-null value in the column Year, create a new group. Option @i means creating a new group when the condition is satisfied. Assign the sum(Water) of the current group to the first row of each group, and create a new data set and take out the TotalWater.


Download esProc Desktop for FREE and kick off 2025 with productivity 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

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.