Conditional Ranking in Excel using SUMPRODUCT Function [RANKIF]

First of all, just do this for me, open your Excel workbook and try to type RANKIF. You will be wondered that there is no function in Excel for conditional ranking.

everytime use sumproduct for conditional ranking

Yes, there is no one.

Now, just think this way, have you ever faced a situation where you have to rank values by using some specific criteria?

And if yes, then how you solved that problem, because you know there is no RANKIF function in Excel.

Not sure?

Let me tell you something, whenever you want to create a conditional ranking based on a specific criterion or category wise ranking, the best way is to use SUMPRODUCT.

Yes, you get it right, it’s SUMPRODUCT.

every time use sumproduct for conditional ranking

data table to use to create rank if with sumproduct for conditional ranking

Here our target is to rank all the students in each of the subjects. That means, ranking from first to the last student in each subject like Finance, Operations and so on, according to their marks

Conditional Formula to use as RANKIF 

  • First of all, add a new column at the end of the table and name it “Subject Wise Rank”.
add new column to data table to create rank if with sumproduct for conditional ranking
  • Now, in the D4 cell, enter this formula =SUMPRODUCT((–(C2=$C$2:$C$121)),(–(B2<$B$2:$B$121)))+1 and hit enter.
add formulas to data table to create rank if with sumproduct for conditional ranking
  • After that, apply that formula to the end of the column, up to the last cell.
drop down formula to data table to create rank if with sumproduct for conditional ranking

Congratulations, you have added subject wise ranks for the students, and do you believe you took a few seconds.

How this Conditional RANKIF Formula works

break down formulas to data table to create rank if with sumproduct for conditional ranking

Part-1: Compare Names

In the first part, you have used (–(C2=$C$2:$C$121)) to compare a subject name with the entire range.

And, it will return an array in which all those values will be true which are matched with the subject name “Finance”.

To check, just edit your formulas in cell D4, select only first part of the formula and press F9. It will show all the values of the array.

Here all the values which are matched with the subject name from the cell D4 are TRUE and the others are FALSE.

So the point is, it has returned a TRUE in the entire array where the subject name is matched.

check first part of the formula to data table to create rank if with sumproduct for conditional ranking

And in the end, you have to use double minus sign to convert TRUE and FALSE into 1 and 0.

check first part of the formula with minus sign to data table to create rank if with sumproduct for conditional ranking

Result from this part of the formula: We have a 1 where the subject is matched and 0 where the subject is not matched.

Part-2: Check Greater than Values

In the second part, you have used (--(B2<$B$2:$B$121)) to check other student's score which is greater than the Tameka's score.

And, it returns an array in which all the values are TRUE where marks are greater than Tameka.

To check, just edit your formulas in cell D4, select only second part of the formula and press F9. It will show all the values of the array.

Here all the values which are greater than "24" are TRUE and others are FALSE.

So the point is, it has returned a TRUE in the entire array where the scores are greater than "24".

check second part of the formula to data table to create rank if with sumproduct for conditional ranking min

And in the end, you have to use double minus sign to convert TRUE and FALSE into 1 and 0. Now, it will look like this.

check second part of the formula with minus sign to data table to create rank if with sumproduct for conditional ranking

Result from this part of the formula: We have a 1 where the score it greater and 0 score where the score is equal or lower than.

Part-3: Multiply Two Arrays

Now, take a deep breath and relax. Slow down your mind and think like this, at this point, we have two different arrays.

  1. In the first array, you have 1 for all values where the subject is matched and 0 if not matched.
  2. In the second array, you have 1 for all the values where the score of the students are greater and 0 if equal or lower.

Now, when SUMPRODUCT multiplies these two arrays you will get 1 only for those students whose subject is matched and the score is greater than Tameka.

check both parts of the formula to data table to create rank if with sumproduct for conditional ranking

Just look at this, there are 9 other students with greater than marks from Tameka in Finance.

number of students have more marks check with the formula to data table to create rank if with sumproduct for conditional ranking

Part-4: Adding + ONE

If you are curious to know about why we need add 1 in the final formula then here is the reason for this.

At this point, you know that the total 9 students are there whose marks are greater than Tameka. So, if 9 students are there then Tameka should be on 10th rank.

That's why you need to add 1 at the end of the formula.

final with the formula to data table to create rank if with sumproduct for conditional ranking

Sample File

Conclusion

If you ask me, I believe SUMPRODUCT function is one of the most powerful functions in Excel library. And, the method we have used above is simple and effective.

With SUMPRODUCT, you don’t need to write long nesting conditional formulas. You just need this magic trick to add conditional ranks.

Now, tell me one thing.

Is this method is useful for you? Have you ever tried any other method for this?

Please share your views with me in the comment section, I’d love to hear from you. And, please don’t forget to share this tip with your friends.