title: Rank duplicate text values in Excel by order of occurrence for unique criteria
body: <p>In Excel I have results data that is ordered in a list similar to below. I am looking for a formula to rank the 'class' column. I have come up with the following which seems to work, but without considering the 'unique' RaceID column.</p>
  
  <pre><code>={COUNTIF(Class,"&lt;"&amp;C2)+SUM(IF(C2=$C$2:C2, 1, 0))-(SUMPRODUCT(--(C2&gt;C$2:C$11))+1)}
  </code></pre>
  
  <p>Where 'Class' refers to 'C:C'.</p>
  
  <p>Unfortunately this would produce a result of '4' for Class A in cell E7, even though Daniel was the race winner for RaceID 0002.</p>
  
  <p>The fifth column is the <em>desired</em> output.</p>
  
  <pre><code>Col A     Col B          Col C    Col D     Col E
  RaceID    Overall Pos    Class    Name      Class rank
  0001      1              A        Jack      1
  0001      2              A        Matt      2
  0001      3              A        Daniel    3
  0001      4              B        Gordon    1
  0001      5              B        Phillip   2
  0002      1              A        Daniel    1
  0002      2              A        Matt      2
  0002      3              B        Günther   1
  0002      4              B        Gordon    2
  0002      5              A        Jack      3
  </code></pre>
  
  <p>What I need is to be able to extend this formula to only rank when the RaceID values match the current row. I'm sure this shouldn't be that difficult, but I'm struggling to complete the formula.</p>