Why does this Index Match Work

Copper Contributor

INDEX('last week sales'!U:U,MATCH(1,('last week sales'!W:W=LARGE('last week sales'!W:W,B128))*(COUNTIF($C$127:C127,'last week sales'!U:U)=0),0))

 

Where U is a list of products and W is the sales for each product. This formula WORKS and gives a ranked list of SKUs from largest to smallest with no duplicates (like if there's two SKUs with the same amount of sales, it gives me each SKU, not the same SKU twice).

 

C127 is where my output starts (header)

B128 is where I have my ranking, ie. 1 being the 1st largest number in the data set and so on.

 

This formula works perfectly, but like I don't understand why or how it works. Please provide an explanation so I can use it for other purposes. What does each component do?

 

 

 

2 Replies

@neny2000 

INDEX('last week sales'!U:U,MATCH(1,('last week sales'!W:W=LARGE('last week sales'!W:W,B128))*(COUNTIF($C$127:C127,'last week sales'!U:U)=0),0))

 

This formula works perfectly, but like I don't understand why or how it works. Please provide an explanation so I can use it for other purposes. What does each component do?

 

You are to be commended for asking. and for seeking to learn. Normally I'd try to explain it, but that formula makes a lot of references to other sheets, and has functions embedded in functions, such that it would be pretty difficult to break it all apart in meaningful ways without access to the whole workbook.

 

And, in fact, since YOU have that access to the whole, you might consider doing that very thing: break the formula down into its various components, working from the inside out, understanding (for example) what 

=(COUNTIF($C$127:C127,'last week sales'!U:U)=0)

yields

and then do the same with each of these in turn

=LARGE('last week sales'!W:W,B128)

=('last week sales'!W:W=LARGE('last week sales'!W:W,B128))

=MATCH(1,('last week sales'!W:W=LARGE('last week sales'!W:W,B128))*(COUNTIF($C$127:C127,'last week sales'!U:U)=0),0)

 

And then, finally, put it all together.

 

To help you along with more explanations of each function as such, here are links to very complete descriptions of each of them and how they work, how to use them.

INDEX

MATCH

COUNTIF

LARGE

 

When you're done, if you're in a position to do this, you might want to approach whoever created the spreadsheet in the first place and ask that in the future they provide documentation on their work, so that it can be both understood and (more importantly) maintained by other people, without having to start from scratch. That's just good development practice.

so I see mathetes already replied but I think I can add to this (I've had it open in a tab to "get to" and hadn't until now).
So 2 things: a) I will break down the formula for you so you can learn but b) if you have new version of excel (like 365) then you should consider some of those new functions.
INDEX('last week sales'!U:U,
MATCH(1,
('last week sales'!W:W=LARGE('last week sales'!W:W,B128))
*(COUNTIF($C$127:C127,'last week sales'!U:U)=0)
,0))
so the formula is chopped into lines above
1st line is just the column you want to index
2nd line is that you want to match 1 to some array of conditions
3rd line is comparing every value in W to the Nth largest value in W (i.e. each line that is that Nth largest will be a 1 and all others will be 0)
4th line is performing a UNIQUE function and giving a 1 for each value that is unique and 0 for values that match prior given results
5th line closes the match with setting it for exact match and closes index
So by mutlipling the 3rd and 4th lines is like an AND operation so it will show the Nth largest value on the Nth line and will 'skip' that line if the Nth largest value was already in the list above that line. That said I think you could use COUNTIF(C127 instead of COUNTIF($C$127:C127 because you only care if it is a repeat of the one immediately before and not a repeat of any item before. Slightly more efficient.
Hope that helps
That all said you can now use UNIQUE(SORT('last week sales'!U:U)) to get a unique sorted ranked list but if I analyzed your formula right it will look slightly different in that it will be a list with no gaps.