Home > database >  Multiply two ranges in Excel to get an array result
Multiply two ranges in Excel to get an array result

Time:11-27

Excel 365 allows to multiply ranges to get an array as a result.

Example:

# A B C
1 1 0 1
2 0 1 1

Entering in A3 = A1:C1 * A2:C2

will evaluate to {1,0,1} * {0,1,1}

and return an array {0,0,1} spilling in A3:C3

# A B C
3 0 0 1

This operation can also be used in formulas, especially useful in FILTER(), SUMPRODUCT() etc.

Is there a formula in Excel 365 that can take as arguments an arbitrary number of 1-D ranges, multiply them, and return a 1-D array in the same way as above?

For what I found out so far, SUMPRODUCT() and MMULT() can return only a single value, not a 1-D array.

Alternatively, I can write a LAMBDA, but would like to avoid it, if there is a ready-made formula for it.

CodePudding user response:

I am not 100% what do you mean, I would assume you want to multiply all rows of the same column and return a row array with the result per column. You can achieve it in cell E1 using the following formula:

=BYCOL(A1:C3, LAMBDA(col, PRODUCT(col)))

and here is the output:

sample excel file

If you have only positives numbers, then you can use MMULT, based on the following mathematical properties:

log properties

Putting in excel terms using EXP/LN functions in our case it would be:

=EXP(MMULT(TOROW(ROW(A1:C3)/ROW(A1:C3)), LN(A1:C3)))

or using LET to avoid repetitions:

=LET(rng, A1:C3, rows, ROW(rng), u, TOROW(rows/rows), EXP(MMULT(u, LN(rng))))

You get the same result.

Note: rows/rows just returns the unit vector with the same number of rows as A1:C3.

  • Related