0

I've created a simple table and trying to split data with subtotals.

enter image description here

  • A indicates the subtotal lines.
  • B contains the rows number for previous subtotal. This is just extra field to simplify formulas.
  • C Contains some amounts.
  • D Contains subtotals of amounts between previous and current subtotal line.

The subtotal formula has the following view:

=ArrayFormula(
    IF($A2:$A; MMULT(
        ($B2:$B < TRANSPOSE(ROW($A2:$A))) * (TRANSPOSE(ROW($A2:$A)) < ROW($A2:$A)); 
        IF(ISNUMBER(C2:C); C2:C; 0)
    ); )
)

The problem is that the formula is extrimely slow. Is there a way to make it faster?

Example file:

https://docs.google.com/spreadsheets/d/1HPGeLZfar2s6pIQMVdQ8mIPzNdw2ESqKAwZfo4IicnA/edit?usp=sharing

raacer
  • 5,302
  • 3
  • 27
  • 46

3 Answers3

1

You could also try this much simpler formula:

=ArrayFormula(
   if(B3:B="","",
         sumif(row(B3:B),"<="&row(B3:B),C3:C)-
         sumif(row(B3:B),"<="&B3:B,C3:C)
   )
)

enter image description here

Tom Sharpe
  • 30,727
  • 5
  • 24
  • 37
0

Yes there is

The easier is to remove the blank rows below the data range.

One that might require maintenance, replace open reference like $A2:$A by closed references, i.e. $A2:$A100

One that incresase the formula complexity an volatility, put each open reference inside ARRAY_CONSTRAIN but it's easier to maintain in case that new data rows were added

Rubén
  • 34,714
  • 9
  • 70
  • 166
0

use the "necessary" range:

=ARRAYFORMULA(IFERROR(IF(A2:A; MMULT((
 INDIRECT("B2:B"&MAX(IF(B2:B="";;  ROW(B2:B)))) < TRANSPOSE(ROW(
 INDIRECT("A2:A"&MAX(IF(A2:A=TRUE; ROW(A2:A); )))))) * (TRANSPOSE(ROW(
 INDIRECT("A2:A"&MAX(IF(A2:A=TRUE; ROW(A2:A); ))))) < ROW(
 INDIRECT("A2:A"&MAX(IF(A2:A=TRUE; ROW(A2:A); ))))); IF(ISNUMBER(
 INDIRECT("C2:C"&MAX(IF(C2:C="";;  ROW(C2:C)+1)))); 
 INDIRECT("C2:C"&MAX(IF(C2:C="";;  ROW(C2:C)+1))); 0)); )))

this should be way faster...

0

player0
  • 124,011
  • 12
  • 67
  • 124