12 responses

  1. Anish
    June 2, 2016

    What about IFERROR(VLOOKUP(B4,$B$3:C4,2,FALSE),MAX(C3:C4)+1), can omit one sum function.


  2. Jacob
    June 3, 2016

    I know it is simple, but not EASY.. Thanks to inspire me.


  3. Nikki
    June 3, 2016

    This is going to be very useful, thanks Chandoo.

    Fellow mango lover 🙂


  4. Sandeep
    June 3, 2016

    Hi Chandoo,

    I seen your site recently and learned excel a lot thanks a ton for all your contributions……….

    The solution striked to me for the above is

    In column E we can filter all the duplicates (these are dynamic) and In column F serial no 1 to 10 (These are static)

    In column B we use vlookup formula…

    This may be not the accurate solution but I given one more solution…

    Plz correct me if i am wrong


  5. Kuldeep
    June 4, 2016

    Awesome as usual 🙂


  6. Cary
    June 6, 2016

    I would have used the following formula in cell C4 and copied it down to the remaining cells (although your formula is much more concise!) :



  7. David N
    June 14, 2016

    Unlike the solution from Chandoo’s file and the solutions from previous comments, this one is different because it does not reference the answers/results from previous rows. It is shown referencing B4 and could be copied down to cover the other rows, but getting the correct answer for row 10 (as an example) does not require that the formula be entered for rows 4-9 as well.



    • Anish
      June 15, 2016

      Dear David,
      Great formulation but it will be easy to learn if you could please explain how the formula works.


      • David N
        June 16, 2016

        Since I mentioned row 10 in my original post, let’s use that for this example. The first MATCH assigns a unique number to each value corresponding to the position of its first occurrence in the list.


        The advantage is that those numbers are in a sort of ascending order, very much like using the RANK function, only with position being what is important as opposed to size. Then the combination of the second MATCH and the COUNTIFS is borrowed from a trick for getting a rank (without using the RANK function) where there are no skips in the sequence for duplicate values. It considers if the current value's first position is less than the first position of all other values and divides by the number of times each value appears in the list.


        This effectively creates an array of fractions that allow us to cheat our way into an accurate count. Here we see the ones (trues) in the numerator correspond to the eights and fours in the denominator such that we have 1/8 a total of 8 times and 1/4 a total of 4 times, with all other fractions equating to zero.

        Finally, SUMPRODUCT adds up the fractions for a total of 2, and the +1 increments that count because the 20 on row 10 is in fact the 3rd unique value in the list. Technically, I could even have used an LTE (less than or equal to) between the two MATCH functions and avoided the need for a +1.


  8. Matt
    June 22, 2016

    Simplest, but less elegant, solution would be to sort the values in B. Then set C4


    Of course, this assumes there is no intrinsic meaning to the cluster IDs (ie, 12 doesn’t have to be 1) which isn’t exactly clear from the question.


  9. Davidlynne
    July 2, 2016

    Its Awesome way to learn the lesson.Thanks for posting this.


  10. Rahul Mangla
    October 13, 2016

    I entered numbers in F13 TO F23 and formula started from G16. Default value in G15=1



Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
mobile desktop