Hi ,
I'll explain Lori's formula , as that is the one which you should be using , since it will work in every situation.
The formula , which is :
=SUM(IF(FREQUENCY(MATCH(A2:A10,A2:A10,0)-1,MATCH(A2:A10,A2;A10,0)-1/RANK(B2:B10,B2:B10)),B2:B10))
makes use of 5 functions ; out of these , the use of SUM and IF needs no explanation. The remaining 3 can be explained as follows :
1. What does the MATCH function do , when the first parameter is not a single value , but a range of values ?
It returns an array of values.
The segment :
MATCH(A2:A10,A2:A10,0)
will return an array as follows :
{1;2;3;1;1;2;7;2;3}
What this means is that the first 3 values are unique , to be found in the first , second and third cells in the range i.e. in cells A2 , A3 and A4.
The fifth and sixth values are the same as the first value ; the seventh value is the same as the second value , and so on.
Subtracting 1 from this returns the array :
{0;1;2;0;0;1;6;1;2}
----------------------------------------------------------------------------------
2. What does the FREQUENCY function do ? Using the following construct :
FREQUENCY(MATCH(A2:A10,A2:A10,0) , MATCH(A2:A10,A2:A10,0))
or even
FREQUENCY(MATCH(A2:A10,A2:A10,0) - 1 , MATCH(A2:A10,A2:A10,0) - 1)
would have returned the following array :
{3;3;2;0;0;0;1;0;0;0}
What this tells us is that the first value in the range A2:A10 occurs 3 times , the second value occurs 3 times , the third value occurs 2 times , while the seventh value ( Johnson ) occurs only once.
The FREQUENCY function returns a value against the first occurrence of an item , and returns zeroes for other occurrences of that item. Thus , against the first occurrence of Smith there is a 3 , while against the second and third occurrence of Smith , there are zeroes.
So far , there is nothing which gives us an indication of how this can ever help us towards a solution. Now comes the surprising twist - the use of the RANK function !
The RANK function ranks the values of the Sales from 1 through 9 , with 1 being assigned to the maximum sales value , and 9 being assigned to the minimum sales value.
Now what happens when we use this along with the MATCH function as the second parameter to the FREQUENCY function ?
Instead of returning the array of values
{0;1;2;0;0;1;6;1;2}
we have an array of values
{0.8;1.5;2.88888888888889;0.857142857142857;0.833333333333333;1.75;6.875;1.66666666666667;2}
Let us see what happens when the FREQUENCY function is used with the above 2 arrays.
Suppose we take the first name Smith ; there are 3 occurrences of the same name , in the first , fourth and fifth cells of the range.
The sales values corresponding to these 3 occurrences of Smith are 20 , 15 and 16.
The RANK function gives these occurrences ranks of 5 , 7 and 6.
By using this as the divisor , 1/RANK will result in a higher value corresponding to the rank of 5 than 6 and 7. Since we are subtracting this result , the higher value being subtracted will give us a lower value corresponding to a rank of 5 compared to the ranks of 6 and 7.
Hence , the three values corresponding to Smith , instead of being 0 , 0 , 0 , are now 0.8 , 0.857 and 0.833
Assigning the value of 0 from the first parameter into the bins will naturally assign it to 0.8
The lowest value of 0.8 now corresponds to the maximum sales of 20.
Similarly , if we consider John , there are 3 occurrences of the same name , in the second , sixth and eighth cells of the range.
The sales values corresponding to these 3 occurrences of John are 47 , 21 and 24.
The RANK function gives these occurrences ranks of 2 , 4 and 3.
By using this as the divisor , 1/RANK will result in a higher value corresponding to the rank of 2 than 4 and 3. Since we are subtracting this result , the higher value being subtracted will give us a lower value corresponding to a rank of 2 compared to the ranks of 4 and 3.
Hence , the three values corresponding to John , instead of being 1 , 1 , 1 , are now 1.5 , 1.75 and 1.66
Assigning the value of 1 from the first parameter into the bins will naturally assign it to 1.5
The lowest value of 1.5 now corresponds to the maximum sales of 47.
Thus , using the 3 functions MATCH , RANK and FREQUENCY ensures that the result will have non-zero values in those places corresponding to the maximum sales figures for each person ; the IF function now retrieves those values , while the SUM function is the final piece of the puzzle.
Narayan