An effort to explain the solution graciously provided by @bosco_yip ...
The key to this question is to find the row number of each specific instance. Once we get the row number, we can use INDEX
as we already have the range ($S$2:$T$10) and the column number (2) we want.
To get the correct row numbers, we use the AGGREGATE
function (documentation here: https://exceljet.net/excel-functions/excel-aggregate-function), which takes four arguments:
- the operation to be performed (the 15 in the formula, which represents the function
SMALL
)
- how to treat certain values (the 6 in the formula, which represents ignoring error values)
- the array being looked at
- which nth value in the array to evaluate.
Since we have the first two arguments of the function, we turn our attention to generating the array, which we get with ROW($A$1:$A$9)/($S$2:$S$10=LARGE($S$2:$S$10,ROW(A1)))
. There are two clever tricks that make this solution work without strict array formulas -- changing the array that the function looks at for each row, and utilizing formulas that spill over data to create the array.
The first part of the formula is given by =($S$2:$S$10=LARGE($S$2:$S$10,ROW(A1)))
For each row, this creates a True/False Array that looks like the below. Notice row i generates an array whose value is true wherever the ith largest value in the range is met.

We would like to take this a step further and instead have each array display the row number where the ith largest value in the range is. To do so, we simply divide another range of numbers 1:9 by the prior array since "TRUE" is crudely evaluated as 1 and "FALSE" as 0. This gives us the following array for each row (recall we exclude errors in the AGGREGATE
function with a second of "6").

We now have the array for each row and turn our attention to the last argument of the AGGREGATE
function. If the jth greatest number in our original data is repeated k times, then we need k separate arguments for each array. We get these separate arguments by using the below formula:
SUMPRODUCT(0+LARGE($S$2:$S$10,ROW(INDIRECT("1:"&ROW(A1))))=LARGE($S$2:$S$10,ROW(A1))))
The first part of this formula, LARGE($S$2:$S$10,ROW(INDIRECT("1:"&ROW(A1))))
generates an array that simply lists the elements in our original data from greatest to least up to the first i items for row i. As an example, the array generated for row 6 would be c(4,3,3,3,3,2).
Each ith array is then tested against the ith largest value in the original data to generate a TRUE/FALSE array as shown below.

Finally, we use SUMPRODUCT
on the array (SUMPRODUCT
of a single array is the same as adding the array) to count the number of entries that are true (note that SUM
or SUMIF
or COUNTIF
will not work). So the ending value of the AGGREGATE
function is shown below (different colors represent different values in the original data) next to the results of the entire function
