keepcalculator

06 Numbers and Powers

Nth Largest Without Duplicates? A Clear Guide

Card No. 06·22293 · Updated · Standard formula, shown below

Nth largest (no duplicates) 0.00
Values (comma-separated)
53839591
You entered
N (rank)
3
You entered
You enter
Values (comma-separated), N (rank)
You get
Nth largest (no duplicates)
Rounding
2 dp

To find the nth largest value in a list while ignoring duplicates, you first extract the unique values from the list, then sort them in descending order and pick the nth one. This is different from simply using a standard “LARGE” function, which counts duplicates as separate entries. The exact method depends on your tool (Excel, Google Sheets, SQL, Python, etc.), but the core logic is the same: deduplicate first, then rank.

Formula

The general formula for the nth largest unique value is:

nth largest unique = SORT(UNIQUE(list), descending)[n]

Where:

  • list is your original set of numbers.
  • UNIQUE(list) removes all duplicate values, leaving only distinct numbers.
  • SORT(…, descending) orders those unique numbers from largest to smallest.
  • [n] selects the nth item from that sorted list (1 = largest, 2 = second largest, etc.).

In spreadsheet terms, this is often written as:

=INDEX(SORT(UNIQUE(A1:A10),1,-1), n)

Where A1:A10 is your range and n is the rank you want.

Worked Example

Let’s use the default values from the calculator: list = 5,3,8,3,9,5,9,1 and n = 3.

  1. Start with the original list: 5, 3, 8, 3, 9, 5, 9, 1
  2. Remove duplicates (keep only first occurrence): 5, 3, 8, 9, 1
  3. Sort descending: 9, 8, 5, 3, 1
  4. Pick the 3rd value: 5

So the 3rd largest unique value is 5. Notice that if you had used a regular LARGE function on the original list, you would get: 9 (1st), 9 (2nd), 8 (3rd) – which is wrong because 9 is counted twice.

Why Duplicates Cause Problems

Most people first try the built-in LARGE function in Excel or Google Sheets: =LARGE(range, n). This works fine when there are no duplicates, but it fails when duplicates exist. For example, with the list 9,9,8,7, the LARGE function returns 9 for both n=1 and n=2, because it sees two separate 9s. If you want unique values, you need to tell the software to ignore repeated numbers.

This is a common issue in sports rankings (two teams tied for first place), sales leaderboards (two reps with the same sales), or any dataset where ties occur. The correct approach is always to deduplicate before ranking.

How to Do It in Excel and Google Sheets

Modern versions of Excel (365 and 2021) and Google Sheets have a UNIQUE function that makes this easy.

  • Excel 365 / 2021: Use =INDEX(SORT(UNIQUE(A1:A10),1,-1), n). The UNIQUE function returns a dynamic array of unique values, SORT sorts them, and INDEX picks the nth one.
  • Google Sheets: The same formula works: =INDEX(SORT(UNIQUE(A1:A10),1,FALSE), n). Note that in Google Sheets, the sort order is specified as TRUE for ascending, FALSE for descending.
  • Older Excel (without UNIQUE): You can use an array formula like =LARGE(IF(FREQUENCY(A1:A10,A1:A10)>0,A1:A10), n) and press Ctrl+Shift+Enter. This is more complex and less intuitive.

If you don’t have access to these functions, a manual method is to copy your data to a new column, use the “Remove Duplicates” feature (under Data tab), then sort descending and read the nth value.

How to Do It in SQL

In SQL, you can use the DISTINCT keyword to remove duplicates, then ORDER BY and LIMIT/OFFSET to get the nth row.

Example for MySQL/PostgreSQL:

SELECT DISTINCT value FROM table ORDER BY value DESC LIMIT 1 OFFSET n-1;

For SQL Server, you’d use OFFSET ... FETCH instead of LIMIT.

If you want to do it without DISTINCT, you can use a subquery with ROW_NUMBER():

SELECT value FROM (
  SELECT value, ROW_NUMBER() OVER (ORDER BY value DESC) as rn
  FROM (SELECT DISTINCT value FROM table) t
) x WHERE rn = n;

Both methods give you the nth largest unique value.

How to Do It in Python

In Python, you can use the built-in set() to remove duplicates, then sort and index.

def nth_largest_unique(lst, n):
    unique_sorted = sorted(set(lst), reverse=True)
    return unique_sorted[n-1]  # n is 1-indexed

Example: nth_largest_unique([5,3,8,3,9,5,9,1], 3) returns 5.

If you want to handle cases where n is larger than the number of unique values, you should check the length first and return an error or None.

Common Mistakes and Pitfalls

  • Forgetting to deduplicate: The most common mistake is using LARGE directly and getting wrong results when there are ties.
  • Off-by-one errors: Remember that n=1 is the largest, n=2 is the second largest, etc. In programming, if you use 0-based indexing, you need to subtract 1.
  • Sort order: Always sort descending. If you sort ascending, you’ll get the nth smallest instead.
  • Ignoring text or blanks: Some functions may treat text as 0 or ignore it. Make sure your data is purely numeric.
  • Using the wrong n: If n is larger than the number of unique values, you’ll get an error. Always check that n ≤ count of unique values.

When to Use This vs. Other Methods

If you need the nth largest with duplicates counted (e.g., “the 3rd highest score, even if tied”), use LARGE directly. If you need the nth largest unique value (e.g., “the 3rd distinct highest score”), use the deduplication method described above.

There’s also a third scenario: you might want the nth largest value but only count duplicates once, yet still show the original value. For example, if you have 9,9,8,7, the 2nd largest unique is 8. The method above gives you that correctly.

If you’re working with a large dataset, consider using a database or a dedicated tool like Python or SQL, as spreadsheet formulas can become slow with thousands of rows.

Frequently Asked Questions

What is the difference between LARGE and this method?

LARGE counts duplicates as separate entries. For example, in the list 10,10,9,8, LARGE(…,2) returns 10 because there are two 10s. The unique method returns 9 as the 2nd largest distinct value.

Can I use this for text values?

Yes, the same logic applies to text. You can find the nth largest alphabetically (or nth smallest) by sorting unique text values. In Excel, use the same formula with a range of text; in Python, the sorted() function works on strings as well.

What if my list has blank cells or errors?

Blank cells are usually ignored by UNIQUE and LARGE, but errors can cause problems. In Excel, you might need to use IFERROR to handle them. In Python, you can filter out None or NaN values before processing.

How do I get the nth smallest unique value instead?

Simply sort ascending instead of descending. In Excel, change the sort order to 1 (ascending). In Python, use sorted(set(lst)) without reverse=True.

Is there a way to do this without a helper column?

Yes, using the UNIQUE function in modern Excel/Sheets is a single formula. In older Excel, you can use an array formula with FREQUENCY. In SQL, you can use a subquery. All avoid helper columns.

What if n is larger than the number of unique values?

You’ll get an error. In Excel, you can wrap the formula in IFERROR to return a custom message. In Python, check the length and return None or raise an exception.

Related

Formula used
in list | Values (comma-separated) | - | 5,3,8,3,9,5,9,1 | 0
in n | N (rank) | - | 3 | 1
out result | Nth largest (no duplicates) | - | 0 | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →