I was trying to grab a range of data using an array as an input to an INDEX (the array in the real formula comes from a MATCH). But the formula I came up with only returns the first hit (Cell A1): answer 1 rather than the sum of rows 1 and 2 as I intended. This is regardless of whether I ENTER or CSE the formula, or even wrap the INDEX in "N()". Is there a way I can grab multiple cells in one INDEX function? I was trying to avoid volatile functions since I have tens of thousands of data points in several tables.
=SUMPRODUCT(INDEX(A1:C4,{1,2},1))
Data rows 1-4 of columns A-C:
1</SPAN>
| 1</SPAN>
| 1</SPAN>
|
2</SPAN>
| 2</SPAN>
| 2</SPAN>
|
3</SPAN>
| 3</SPAN>
| 3</SPAN>
|
4</SPAN>
| 4</SPAN>
| 4</SPAN>
|
<TBODY>
</TBODY>
=SUM(OFFSET($A$1,0,{0,1},2,3))
would be a somewhat obvious set up.
Using INDEX instead of OFFSET requires specifying rows 1 and 2 plus all columns of A1:C2. That is:
SUM of INDEX(A1:C4,1,0) + SUM of INDEX(A1:C4,2,0)
[1] The following won't work:
SUM(INDEX(A1:C4,{1;2},{0,0}))
for the formula cannot interpret {1;2} as rows 1 and 2 and {0,0} as all cells of the rows in question.
A possible way is to use a function for dereferencing or a function for a second round of evaluation. [ The OP appears to be aware of N which can effect the required dereferencing (other functions that are used for the same purpose are SUBTOTAL and TRANSPOSE). ]
Composing an array constant is often done with CHOOSE
CHOOSE(1,{1;2})
as with IF (I saw at least once someone using it)...
IF(1,{1;2})
However, the following won't still not succeed as intended:
SUM(INDEX(A1:C4,CHOOSE(1,{1;2}),CHOOSE(1,{0,0})))
unless we add a dereferencer:
SUM(INDEX(A1:C4,N(CHOOSE(1,{1;2})),N(CHOOSE(1,{0,0}))))
Confirmed with control+shift+enter, not just enter, this formula will achieve the intended sum. Substituting IF for CHOOSE, we would have:
=SUM(INDEX(A1:C4,N(IF(1,{1;2})),N(IF(1,{0,0}))))
also to be confirmed with control+shift+enter.
Keywords for searching with Google, for example: dereferencing (also "deferencing", a typo I committed at least once), second round of evaluation, CHOOSE (also interesting to see how CHOOSE is used to construct a reference involving non-contiguous cells).