• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

=INDEX(array,MATCH(array,array))

eibi

Active Member
Given the data in range A1:B6:

black, 2
brown, 1
green, 3
orange, 6
pink, 3
purple, 2

and a set of test values in range D1:D10

green
purple
pink
orange
purple
brown
black
green
orange
pink

When I create an array formula:

{=MATCH(D1:D10,A1:A6,0)}​

The formula returns an array:

{3;6;5;4;6;2;1;3;4;5}​

Good. I can use this array as input for all manner of other formulas.

But. Suppose I want to use it in an INDEX() formula to lookup and sum the corresponding value (from column B) for all the test values in column D.

I would expect:

{=SUM(INDEX(B2:B6,MATCH(D1:D10,A1:A6,0)))}​

to return:

{=SUM(INDEX(B2:B6,{3;6;5;4;6;2;1;3;4;5}))}​

and then:

{=SUM({3;2;3;6;2;1;2;3;6;3})}​

resolving to a friendly 31 :)

But instead, it ignores the MATCH() array:

{=SUM(INDEX(B2:B6,MATCH(D1:D10,A1:A6,0)))}​

and behaves as though I wanted it to:

{=SUM(INDEX(B2:B6,MATCH("green",A1:A6,0)))}​

which resolves to a useless 3 o_O

I really want to use an =INDEX(array,MATCH(array,array)) application. But I can't figure it out.

A helper column is an unsavory work-around.

Any suggestions? Am I doing it wrong?
 

Attachments

  • eibi1.xlsx
    8.6 KB · Views: 13
Last edited:
@azumi -- Great workaround, and a great solution for the example I provided. However, my actual application isn't always a "sum" function -- sometimes I need to return an array of text strings and further evaluate them, so I'm looking for a way to pass an array as the first argument to a MATCH() nested in an INDEX().

@XOR LX -- I'm already a follower of your blog, where I've learned so many new ideas -- but it has so much content in such a concise format that I digest it very slowly. I will give your suggestion some study and try it out in a few different applications.

Thanks all!!!
 
Back
Top