How to Rank Text Uniquely in Google Sheets

Published on

Using a combination of two conditional count functions, we can rank text values uniquely in Google Sheets. They are Countif and Countifs.

Earlier I have shared a formula to rank data alphabetically. We can’t use the same here as that will give the same rank to duplicate texts.

For example, if “apple” repeats twice and the rank of apple is 1 in the list, both will get the rank 1.

When we rank text values uniquely without duplicates, the first “apple” will get rank # 1, and the second “apple” will get rank # 2. It will affect the ranking of other text values in the list.

Before going to the formula part, one more thing.

You may have a list that is sorted or unsorted. My formula will work smoothly in both scenarios.

Please pay attention to column C in the following two tables.

Unsorted (Randomized) List:

Rank Text Uniquely in an Unsorted List

Sorted List:

Rank Text Uniquely in a Sorted List

Unique Rank of Texts

Generic Formula:

Unique Rank of Text = Count_of_Text_Below + Running_Count_of_Text

Arguments:

Count_of_Text_Below – The number of texts < (less than) the text in question. To understand it, let’s consider the above-sorted list.

The cells B2, B3, and B4 contain “apple.” There is no text less than it. So the count of text below will be 0 (zero) each.

What about the count of “grape” in cells B5 and B6. It will be three each as there are three items (apples) less than it below.

Running_Count_of_Text – In the sorted list, the running count of “apple” in cells B2, B3, and B4 will be 1, 2, and 3, respectively.

What about the running count of “grape” in cells B5 and B6. It will be 1 and 2, respectively.

Based on the above, we can rank texts uniquely as below in Google Sheets.

Item Count_of_Text_Below Running_Count_of_Text Unique Rank of Text
apple011
apple022
apple033
grape314
grape325

Note:- I have only picked part of the items from the sorted list for the explanation.

Formulas to Rank Text Values Uniquely in Google Sheets

We will start with a drag-down formula.

Here is the formula to return the rank of text values uniquely in Google Sheets. Insert it in cell C2 and copy-paste it down as far as needed.

=COUNTIF($B$2:$B,"<"&B2)+COUNTIF($B$2:B2,B2)

Count_of_Text_Below = COUNTIF($B$2:$B,"<"&B2)

Running_Count_of_Text = COUNTIF($B$2:B2,B2)

It will work correctly even if the list is unsorted.

Can we use an array formula here?

Yes. Here we can use two count functions. They are COUNTIF and COUNTIFS.

You May Like: How to Use All Google Sheets Count Functions [All 8 Count Functions]

First of all, empty C2:C. Then insert the following array formula in cell C2 to rank texts uniquely.

=ArrayFormula(
     if(B2:B="",,
        COUNTIF(B2:B,"<"&B2:B)+
        COUNTIFS(B2:B,B2:B,row(B2:B),"<="&ROW(B2:B))
     )
)

Count_of_Text_Below – COUNTIF(B2:B,"<"&B2:B)

Running_Count_of_Text – COUNTIFS(B2:B,B2:B,row(B2:B),"<="&ROW(B2:B))

The formula if(B2:B="",, is to limit the output in non-blank rows.

That’s all. This way, you can rank text uniquely without duplicates in Google Sheets.

Thanks for the stay. Enjoy!

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Custom Order for QUERY Pivot Headers in Google Sheets

By default, when you use the PIVOT clause in a Google Sheets QUERY, the...

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

More like this

Custom Order for QUERY Pivot Headers in Google Sheets

By default, when you use the PIVOT clause in a Google Sheets QUERY, the...

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.