In col A subsets of 'Races" are shown. In col B subsets of Horses within each race. The number of which varies from 3 to 24. In col C values left behind in time order after removing duplicates. The most recent value is at the top of each Horses subset. In col D shows the last/most recent value.
In col E the values in col C are ranked against each other, but this is where things get complex. Take cell E2. The value at C2 is ranked against itself, C5,C10,C15,C17,C23. This rank formula is repeated progressing down col E and ranking against the next consecutive value for each horse. However because the number of values for each horse varies, you run out of consecutive values, and in this case the formula uses the last value for each horse.
e.g. Take cell E4. It's ranked against itself, E7, E12,E16* (last value for horse4),E19,E25
The rank formulas are resident in col E, so you can follow what's going on. I've shown 3 races in this example, but in reality there are many tens of thousands of races, horses and values. I should've ranked as I recorded and will in the future. It's a matter of backtracking over old data to extract more information.
From my experience solving this issue with code or formula is nigh on impossible, and anyone that can solve this would be elevated to "Genuis" status IMHO!