Forum Discussion
James_Buist
Oct 21, 2024Brass Contributor
Another spilled array that I can't solve - Aggregating monthly into time periods
This I thought would be quite easy but hit a brick wall at each attempt. In summary, I am trying to use a spilled array to sum up expenses into time periods. So I have a 5 year projection and s...
- Oct 21, 2024
An interesting set of data. I though of unpivoting it first before proceeding but found it more straightforward to use MAKEARRAY.
=LET( i, ROWS(data), j, COLUMNS(data), GetTotals, LAMBDA(r, c, LET( current_row, CHOOSEROWS(data, r), each_period, INDEX(periods, r), start, IFNA(XMATCH(TRUE, current_row <> 0, 1), 0) + each_period - 1, k, ROUNDUP(SUM(N(current_row <> 0)) / each_period, 0), seq₁, SEQUENCE(k, , start, each_period), seq₂, SEQUENCE(each_period, , c, -1), total, SUM(INDEX(data, r, seq₂)), check, XOR(seq₁ = c), result, IF(check, total, 0), IFERROR(result, 0) ) ), MAKEARRAY(i, j, GetTotals) )
Patrick2788
Oct 21, 2024Silver Contributor
An interesting set of data. I though of unpivoting it first before proceeding but found it more straightforward to use MAKEARRAY.
=LET(
i, ROWS(data),
j, COLUMNS(data),
GetTotals, LAMBDA(r, c,
LET(
current_row, CHOOSEROWS(data, r),
each_period, INDEX(periods, r),
start, IFNA(XMATCH(TRUE, current_row <> 0, 1), 0) + each_period - 1,
k, ROUNDUP(SUM(N(current_row <> 0)) / each_period, 0),
seq₁, SEQUENCE(k, , start, each_period),
seq₂, SEQUENCE(each_period, , c, -1),
total, SUM(INDEX(data, r, seq₂)),
check, XOR(seq₁ = c),
result, IF(check, total, 0),
IFERROR(result, 0)
)
),
MAKEARRAY(i, j, GetTotals)
)
James_Buist
Oct 24, 2024Brass Contributor
Brilliant. Works like a dream. I will test it more and study it> I have seen to power of Makearray but never really been able to harness it. I know I will learn a lot from this and am very grateful for your amazing answer. Thanks hugely
Been working out of a third party office with no external access for the past 2 days so only now managing to review and respond.
Just tested more and there is a slight hitch. See follow on post