Google-sheets – Sum rows of a array function that outputs a matrix [Google Spreadsheet]

google sheets

I got a arrayfunction that is returning a matrix. I want to edit this to only return a vector, where this vector contains the sum of each row. I tried applying sum(), but that summed every element of the matrix. It is important to keep it just to one formula, not one array-formula for each row.

I am working in Google Spreadsheet, but If you only know a solution for Excel, please post it, and I might be able to convert it.

Best Answer

In Excel You can also use this version

=SUMIF(OFFSET(A1:C15,ROW(A1:C15)-ROW(A1),0,1),"<9.99E+307")

confirmed with CTRL+SHIFT+ENTER

assuming your matrix is in A1:C15

That has a small advantage over MMULT - it still works if some of the cells in A1:C15 are blank or don't contain numbers

However you can amend the MMULT version to work with a partially populated range too, i.e. with this version

=MMULT(IFERROR(A1:C15+0,0),TRANSPOSE(COLUMN(A1:C15)^0))

again confirmed with CTRL+SHIFT+ENTER

In Google sheets I couldn't make the SUMIF version work - but the MMULT option works with the addition of "arrayformula" function, i.e. this version:

=arrayformula(mmult(iferror(A1:C15+0,0),transpose(column(A1:C15)^0)))