Forum Discussion

James_Buist's avatar
James_Buist
Brass Contributor
Oct 21, 2024

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...
  • Patrick2788's avatar
    Oct 21, 2024

    James_Buist 

    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)
    )

Resources