#39 - Define A Dynamic Range of Columns And Perform Aggregation

#39 - Define A Dynamic Range of Columns And Perform Aggregation

Problem description & analysis:

In the following Excel table, columns are months arranged in order and their displayed names are representations of the corresponding dates. For example, Jan represents 1/1/2023.

ABCD
1
2JanFebMar
3Sales100001500020000
4COGS5000750010000
5Expenses200020002000
6Net Profit300055008000

We want to sum values within the interval defined by the start month and end month parameters defined in G1 and I1.

GHI
Start MonthJanEnd MonthFeb
Sales25000
COGS12500
Expenses4000
Net Profit8500

Solution:

Use SPL XLL to do this:

=spl("=p=(d=?1)(1).pselect@a(between(E(~),E(?2):E(?3))),d.to(2,).(~(p).sum())",B2:D6,G1,I1)

As shown in the picture below:

r/esProc_Desktop - Define A Dynamic Range of Columns And Perform Aggregation

Explanation:

pselect()function gets the positions of the eligible members. (N) represents the Nth member; it represents members at multiple positions when N is an integer sequence. to(2,) gets members from the 2nd to the last; ~ is the current member.