I have a column (column
I don't know in advance how long the sequence will be and I would like to use an array formula to automatically adjust the length of the output, instead of repeating the formula in
The following formula works:
but is much slower than the
How can I make the array formula as fast as the non-array formula?
(and BTW, why is the array formula so slow? All operations inside it should be very fast.)
PS I posted this previously on SU (Fast array formula for running total of a column for consecutive dentical values in another column) but I didn't receive any useful answer there.
E
) with integer values, and another column (F
) with arbitrary values. I want to compute, in column G
, the running total of F
, but limited to the segment of consecutive rows where the current value of F
is constant. The description may be easier to understand with formulas:
Excel Formula:
B2 =100 # Length of sequence
B3 =3 # Possible values in column E
D2 =SEQUENCE(B2) # Auxiliary variable
E2 =RANDARRAY(B2,,1,B3,TRUE) # Sequence of integers between 1 and B3
F2 =RANDARRAY(B2) # Sequence of values to be summed
G2 =IF(OR(D2=1,E2<>E1),0,G1)+F2 # Desired output, non-array formula version.
# If the current value in E is the same
# as in the previous row, sum to the running total of F,
# else start again with the current value of F.
# Formula needs to be copied along the other columns.
I don't know in advance how long the sequence will be and I would like to use an array formula to automatically adjust the length of the output, instead of repeating the formula in
G2
in the G
column.The following formula works:
Excel Formula:
H2 =LET(s,E2#,v,F2#,SCAN(0,D2#,LAMBDA(a,x,IF(OR(x=1,INDEX(s,x)<>INDEX(s,x-1)),0,a)+INDEX(v,x))))
but is much slower than the
G2
formula above: it becomes slow when the sequence has a length in the thousands, while the G2
formula can easily handle hundreds of thousands of values.How can I make the array formula as fast as the non-array formula?
(and BTW, why is the array formula so slow? All operations inside it should be very fast.)
PS I posted this previously on SU (Fast array formula for running total of a column for consecutive dentical values in another column) but I didn't receive any useful answer there.