Hi,
The first part of the formula is
Pay particular attention to the $ signs in here. The first bit $B$5:$B5 fixes $B$5 when the formula is copied down the list. So that when the formula is copied to say row 6 the formula becomes
i.e. the B5 cell reference remains whilst the range of the COUNTIF has expanded to row 6. Similarly when copied to say row 10 it will read =COUNTIF($B$5:$B10,B10)
The effect of this is to count the number of occurencies of B5 (B6, B7..etc in the ranges B5:B5, B5:B6, B5:B7 ..etc.). In other words if there is more than one occurrence of a column B value, on each row where there is an occurrence the COUNTIF() function will record a value of 2,3,4,5 etc.
I suggest you test this out by putting the formula =COUNTIF($B$5:$B10,B10) in another column and copying it down to see the effect.
So knowing where the occurrencies happen, i.e. when the COUNTIF value is > 1 we can then use the MATCH() function to find on which row in the overall $B$5:$B$35 the ID number in column B FIRST occurs. The MATCH() function will return the same row number for each occurrence. So for instance the MATCH function on say row 15 of the original unsorted list will return the value 5, which means the ID 412-0001 in B15 first occurs on row 9, (i.e. the 5th row in the range B5:B35). Similarly the Match function on row 17 (the same ID) again returns the value 5.
So now we know where the first occurrence (in a list that is sorted by Value) of the ID number first appears. Knowing this we can then finally use the INDEX() function to get the UNIT Price value that occurs at the first occurrence of each ID number. If you look at the helper column you'll see that the same Value is returned for each ID and this value is the highest value since the list is first sorted by the Value column.
Of course once the list has been sorted by the helper column, the helper column is no longer working with a column already sorted by Value so any subsequent sort on the helper column would not give the same results. That's why I suggested that after the first sort the helper column values are converted to values. You'll note that I carry a copy of the formula in D1 so that should I ever need to use it again I can simply copy and paste it again - which is a technique that is useful a lot of the time.
Bookmarks