Warm tip: This article is reproduced from serverfault.com, please click

How to convert an "enumerate" to array

发布于 2020-11-28 08:25:26

I am trying to calculate sum(a.*b) = a[1] * b[1] + a[2] * b[2]+.....

The array a with length n is present in the sheet. Values of b though are not present directly. To get b, there is a column of data and n indexes. b[i] = data[indexs[i]]

One way to find sum(a.*b) is to first buffer the value of b using INDEX(data, indexes) and then SUM(a * b). I want it to be done in one cell with no buffering. So I tried replacing b with the formula of b like SUM(a * INDEX(data, indexes)). But excel considers INDEX(data, indexes) to be iterable and gives me [SUM(a * b[1]), SUM(a * b[2]), ...]

How do I tell excel to take INDEX(data, indexes) as an array?

sample

Questioner
Songhao Li
Viewed
0
Tom Sharpe 2020-11-28 16:53:18

In earlier versions of Excel (pre-O365), you have to use the following manoeuvre to deliver an array using Index as described here:

=SUMPRODUCT(D3:D4*INDEX(A2:A10,N(IF({1},B2:B3))))

The curly brackets around the 1 {1} are not strictly necessary, but I tend to leave them in to signal that I am using this trick.

enter image description here