HomeGoogle DocsSpreadsheetTop N Values Including Duplicates in Google Sheets

Top N Values Including Duplicates in Google Sheets

Published on

Assume 50, 49, 48 are the top 3 scores in a cricket match. But two batsmen have scored 48 runs each. Then how to get the scores 50, 49, 48, and 48 when extracting top 3 scores? To filter top n values including duplicates in Google Sheets, you can use SORTN.

With the help of a SORTN formula, Google Sheets users can extract top or bottom n values in Google Sheets. In concise, use this tutorial to get to know;

  1. How to extract or filter to a new range top 3, 5, 10 or n values including duplicates in Google Sheets.
  2. Extracting or filtering to a new range bottom 3, 5, 10, or n values including duplicates in Google Sheets.

Let’s begin with the following sample dataset to extract top n values with duplicates.

Sample Data to Filter to a New Range Top N Values with Duplicates

(Student Names and Their Marks out of 50 in an Exam)

AB
1Roger50
2Johnny48
3Patricia48
4Martha47
5David46
6Jonathan45
7Theresa40
8Ruby38
9Linda29
10Susan29
11Jennifer25
12Louis24

Here do you want the top n marks only or top n marks with the student names?

For example, if you want to extract the top 5 marks, the result would be the marks 50, 48, 48, 47, 46, and 45.

Note: If you count these values, you will get 6 instead of 5 as there is one duplicate mark in the top 5 ranks.

If you want to extract the names too with the marks, the result would be like;

CD
1Roger50
2Johnny48
3Patricia48
4Martha47
5David46
6Jonathan45

I have solutions for both the above scenarios. Here we go!

SORTN to Extract Top N Values Including Duplicates in Google Sheets

As the title suggests, the formula here is based on SORTN. To get only the top 5 values (of course that including duplicates), use the below SORTN formula.

=sortn(B2:B13,5,3,1,0)

In this SORTN formula, B2:B13 is the range containing the marks of the students. The number 5 represents n.

That means to filter top 10 values including duplicates to a new range, change 5 to 10.

=sortn(B2:B13,10,3,1,0)

What about extracting top 10 values including duplicates and corresponding names? Here is that SORTN formula.

=sortn(A2:B13,5,3,2,0)

Here in the formula, I have just included the range that contains the names too. In addition to that changed the sort column to 2 (the column index number containing the marks). The sort column is the fourth argument in the formula.

This way you can extract top 5, top 10, top n values including duplicates in Google Sheets.

Extract Top N Values Including Duplicates in Google Sheets

Extract Bottom N Values Including Duplicates in Google Sheets

In rare cases, depending on your nature of the job assigned, you may require a formula to filter/extract bottom 5, 10 or n values. Don’t worry! The above SORTN formula will come in handy in this case too.

To extract bottom n values, including duplicate values, use the following formula.

=sortn(A2:B13,5,3,2,1)

Just compare this formula with the last formula. What changes do you see?

The change in only in the last argument. Earlier it was the value 0 now it’s 1. Actually it’s sort order.

Extract Bottom N including Duplicates

To filter/extract top n numbers with duplicates, I have sorted the data (numeric column) in descending order.

To get bottom n values, we should sort the data (numeric column) in ascending order. That’s what we have done in the last formula.

Conclusion

In Excel, you might have seen or used a different approach to get top or bottom n values with duplicates.

Why didn’t you see such a smarter solution using SORTN in Excel? My guess, Microsoft has introduced SORTN only in the latest iterations of Excel.

Want to apply the above logic in a Pivot Table in Google Sheets? Then do follow this guide – How to Filter Top 10 Items in Google Sheets Pivot Table.

That’s all for now! Hope you have enjoyed the stay here.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

More like this

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

2 COMMENTS

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.