8

Let's say 3 columns (A, B, C) are dynamic arrays and I want to create a fourth/final dynamic array formula that is the sum of these 3 columns for each row in column D. For clarity, I am looking for the row-by-row sum of each row in this final column.

This will work: =A2#+B2#+C2#

How can the same be accomplished by using the SUM function? The reason I ask is that this is easier to use on larger ranges of data.

The following gives a #REF! error: =SUM(A2:C2#)

9
  • 1
    What is the reason of using # in formula? =SUM(A2:C2) shall work as you need. Commented May 14, 2020 at 12:48
  • Using # converts it into a Dynamic Array formula. This changes its nature completely as now it AUTOMATICALLY adjusts its length to match the size of your data WITHOUT you needing to manually copy your formula every time the length of the data set changes Commented May 14, 2020 at 12:55
  • 1
    @ScottCraner - that doesn't sum row-by-row. Commented May 14, 2020 at 13:08
  • 1
    Ah, I thought they wanted the total, not individual @BigBen Commented May 14, 2020 at 13:09
  • 1
    I do think it's confusing since OP mentioned =A2#+B2#+C2#, while # refers to a spilled range, this would also make me believe OP is after the total. However SUM(A:C) isn't used which then makes me believe he actually is after a row-by-row calculation Commented May 14, 2020 at 13:11

4 Answers 4

20

New Edit:

With the addition of BYROW and LAMBDA we can do this a little easier than my original answer below:

=BYROW(A1#:C1#,LAMBDA(x,SUM(x)))

The BYROW passes each row into the LAMBDA which does the SUM iteratively and returns an array:

enter image description here


Original Answer

The problem is that SUM,MAX,MIN all allow arrays and do the whole on the full array. So we need to use something that uses arrays and spills individual results. That is what MMULT was built for.:

=MMULT(A2#:C2#,TRANSPOSE(COLUMN(A2:C2)^0))

enter image description here


Just realized with the dynamic arrays we have SEQUENCE:

=MMULT(A2#:C2#,SEQUENCE(COLUMNS(A2:C2),,1,0))
Sign up to request clarification or add additional context in comments.

3 Comments

It aint pretty but it works. I was however hoping for something a little more elegant/natural...
@Sam the problem is that SUM,MAX,MIN all allow arrays and do the whole on the full array. So we need to use something that uses arrays and spills individual results. That is what MMULT was built for. I may be wrong but I doubt there will be anything more elegant/natural
@ScottCraner This is excellent! I used it to replace SUMIF(S) on rows. Something like: =MMULT(A2#:C2#,TRANSPOSE(--(A1:C1<myNumber))) or whatever other condition(s) are needed
2

Try this for sums per column (assuming A1# is the dynamic range with the source data):

=SUBTOTAL(9,OFFSET(A1#,0,SEQUENCE(1,COLUMNS(A1#))-1,ROWS(A1#),1))

Just change the first argument of the SUBTOTAL function to use any of the aggregation functions available (min, max, average, etc.). With some tweaks, this can be made to work for row totals.

Comments

1

When I tried Scott Craner's formula above I received a VALUE# error, possibly related to the fact that I was testing it on data columns of different dynamic lengths.

Even though the expression A2#:C2# returns a matrix of width 3 columns, and height of whichever of the three columns has the most rows (filling in zeros for any blank cells), MMULT didn't seem to like that expression and resulting matrix as the first argument. However I found that I was able to modify it as follows to make it work:

=MMULT((A2#:C2#*1),SEQUENCE(COLUMNS(A2:C2),,,0))

Comments

0

Absolute legend. I've been trying to work this out. Thank you so much. I have never used MMULT before, only SUMPRODUCT for similar problems. My problem was to dynamically sum up the last few columns in a spill table and I was able to adapt your solution.

In terms of the question above, if the three spill columns were one spill table with rows and columns in the one spill range it would be:

=MMULT(A2#,SEQUENCE(ROWS(A2#)),SEQUENCE(COLUMNS(A2#)),,1,0))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.