keepcalculator

06 Numbers and Powers

Filter to Show Duplicate Values? How-To

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

To filter a list or table so only duplicate values remain, you use a built-in feature like Excel’s Conditional Formatting combined with a filter, or a dedicated function in tools like Google Sheets, SQL, or pandas. The exact steps vary by tool, but the core idea is the same: identify values that appear more than once, then hide everything else.

What “Duplicate Values” Means

A duplicate value is any entry that appears more than once in a selected column or range. For example, in a list of customer IDs, the ID “A100” appearing twice is a duplicate. Filters that show duplicates typically keep all rows for values that occur at least twice — they do not remove the first occurrence, because that would leave only one copy of each repeated value. The goal is usually to review or edit those repeated entries, not to delete them.

How to Filter Duplicates in Excel

Excel does not have a one-click “filter duplicates” button, but you can combine Conditional Formatting with a filter in a few steps:

  1. Select the column or range you want to check.
  2. Go to Home → Conditional Formatting → Highlight Cells Rules → Duplicate Values. Choose a format (like a light red fill) and click OK.
  3. Now select the same range and go to Data → Filter (or press Ctrl+Shift+L).
  4. Click the dropdown arrow in the column header, choose Filter by Color, and select the fill color you used. Only cells with that color — the duplicates — will show.

This method works for text, numbers, and dates. It treats “Apple” and “apple” as different unless you use a case-insensitive formula. It also considers the entire cell value, so “123” and “123 ” (with a trailing space) are not duplicates.

Filtering Duplicates in Google Sheets

Google Sheets offers a simpler built-in option:

  1. Select the data range.
  2. Go to Data → Data cleanup → Remove duplicates. This deletes duplicates, not just filters them.

To only view duplicates without deleting, use a helper column with a formula like =COUNTIF(A:A, A2)>1. This returns TRUE for rows where the value in column A appears more than once. Then filter the helper column to show only TRUE. This is a flexible approach because you can adjust the range or add conditions (e.g., only duplicates in a specific date range).

Using SQL to Filter Duplicates

In SQL databases, you filter duplicates with the GROUP BY and HAVING clauses. For example, to list all customer IDs that appear more than once in an orders table:

SELECT customer_id, COUNT(*) AS cnt
FROM orders
GROUP BY customer_id
HAVING COUNT(*) > 1;

This returns each duplicate value once, along with its count. To see the full rows of those duplicates, you would join this result back to the original table. In PostgreSQL, you can also use a window function like ROW_NUMBER() to rank rows and then filter where the rank is greater than 1.

Filtering Duplicates in Python (pandas)

In pandas, the duplicated() method returns a boolean Series that marks rows that are duplicates. To filter a DataFrame to show only duplicate rows:

import pandas as pd
df = pd.read_csv('data.csv')
dupes = df[df.duplicated(subset=['email'], keep=False)]

The keep=False argument marks all rows that have a duplicate email, not just the second and later ones. If you want only the second occurrence onward, use keep='first'. This is useful for finding records that were entered twice.

Common Pitfalls and Misconceptions

A frequent mistake is confusing “duplicate rows” with “duplicate values in one column.” Excel’s built-in duplicate formatting works on the selected cells, not entire rows. If you select two columns, it marks rows where the combination of both columns repeats — not where a single column has repeats. To find duplicates in one column while ignoring others, select only that column.

Another misconception is that filtering duplicates will leave one copy. In every tool mentioned, the filter shows all rows that have a duplicate, including the first occurrence. If you want to remove duplicates and keep only unique values, you need a separate “remove duplicates” function, which exists in Excel (Data → Remove Duplicates) and Google Sheets (Data → Data cleanup).

Spaces, punctuation, and case sensitivity are common sources of missed duplicates. “John Smith” and “John Smith” (two spaces) are different values. Leading or trailing spaces are invisible but affect matching. Use the TRIM function in Excel or Sheets to clean data first.

When to Use a Filter vs. Remove Duplicates

Use a filter when you want to review the duplicate rows before deciding what to do. For example, you might want to check if two orders with the same ID are actually different because they have different dates. Use a remove-duplicates function when you are certain the duplicates are errors and you want to keep only one row per value. Removing duplicates is destructive and cannot be undone unless you have a backup, so always save a copy of your data first.

Alternatives for Large Datasets

For very large datasets (hundreds of thousands of rows), Excel’s conditional formatting can slow down. A faster approach is to use a pivot table: put the column you want to check in the Rows area and the same column in the Values area as a count. Then filter the pivot table to show counts greater than 1. This gives you a list of duplicate values without formatting every cell.

In SQL, an index on the column can speed up the GROUP BY query. In pandas, the duplicated() method is efficient even on millions of rows because it uses hashing.

Frequently Asked Questions

How do I filter duplicates in Excel without deleting them?

Use Conditional Formatting to highlight duplicates, then apply a filter and filter by color. This shows only the highlighted cells, leaving the original data intact.

Why does my duplicate filter miss some values?

Check for invisible characters like spaces, or case differences. Excel’s default duplicate rule is case-insensitive but treats “123” and “123 ” as different. Use TRIM to remove extra spaces, and consider using a formula with EXACT for case-sensitive matching.

Can I filter duplicates across multiple columns?

Yes. In Excel, select all the columns you want to check. The duplicate rule will mark rows where the entire selected row is identical. In SQL, you would list multiple columns in the GROUP BY clause. In pandas, pass a list to the subset parameter.

Does filtering duplicates show the first occurrence?

Yes, in most tools. The filter shows all rows that have a duplicate, including the first one. If you want to hide the first occurrence, you need to add a condition that excludes the earliest row, which is more complex.

What is the difference between duplicate values and duplicate rows?

Duplicate values refer to repeated entries in a single column or across selected columns. Duplicate rows are entire records that are identical in every column. The method you use depends on which you need.

Related

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 →