Ravindra BagaleCourses & study guides मराठी Track your progress

5. Data Cleaning A–Z

5.1 Duplicates

Flag duplicates with COUNTIF with example — in 30 seconds

What: A growing range like $A$2:A2 counts how many times an ID has appeared so far. More than 1 means a repeat.

Why: Deleting duplicates blindly can delete real data. A flag column lets you check first, then remove.

Tiny example: BLK-1001 appears in rows 2 and 4. Row 4 is flagged Duplicate. Total flagged: 2.

First look at the data (before → after):

Flag duplicates with COUNTIF with example: before and after tables, fictional FreshGo Maharashtra data

Expected result — Flag column B

A: Order ID B: Flag
BLK-1001 First
BLK-1002 First
BLK-1001 Duplicate
AMN-1003 First
BLK-1002 Duplicate

About this data: Teaching sample for a fictional shop “GreenField Dairy”. Figures and names (e.g. Aarti Kulkarni) are made up for this lesson on duplicates.

Before table and formula as text

Before — Export with repeated IDs

Row A: Order ID
2 BLK-1001
3 BLK-1002
4 BLK-1001
5 AMN-1003
6 BLK-1002

About this data: Demo table only — not real customer or company data. Built to practise duplicates.

Formula / click path

B2: =IF(COUNTIF($A$2:A2,A2)>1,"Duplicate","First")   → copy down

Do it step by step:

  1. Click B2.
  2. Type =IF(COUNTIF($A$2:A2,A2)>1,"Duplicate","First").
  3. Only the first $A$2 is locked. The end of the range grows as you copy down.
  4. Copy down, then filter column B for Duplicate.
  5. Check those rows, then delete them or use Data › Remove Duplicates.

Before

Order ID City Product Amount
BLK-3001 Pune Gokul Cow Milk 500 ml 32
BLK-3002 Nashik Nashik Grapes 500 g 90
BLK-3001 Pune Gokul Cow Milk 500 ml 32
BLK-3003 Nagpur Nagpur Oranges 1 kg 120
BLK-3002 Nashik Nashik Grapes 500 g 90

About this data: Made-up rows so you can copy the pattern for duplicates. Currencies may use ₹, £, € or $.

After

Order ID City Product Amount
BLK-3001 Pune Gokul Cow Milk 500 ml 32
BLK-3002 Nashik Nashik Grapes 500 g 90
BLK-3003 Nagpur Nagpur Oranges 1 kg 120

About this data: Fictional worksheet used in class. Safe to edit; nothing here is live production data.

Steps in Excel

  1. See them first: select Order IDs › Home › Styles › Conditional Formatting › Highlight Cells Rules › Duplicate Values.
  2. Flag with a formula: in E2 =IF(COUNTIF($A$2:A2,A2)>1,"Duplicate","First") – the expanding range $A$2:A2 marks the 2nd, 3rd… copies only. Filter on "Duplicate" to review.
  3. Remove: click inside the data › Data › Data Tools › Remove Duplicates › tick only the columns that define a duplicate (here Order ID; or all columns for fully identical rows) › OK. Excel reports how many were removed – here 2 duplicate values found and removed; 3 unique values remain.
  4. Formula way (Microsoft 365 / Excel 2021+): =UNIQUE(A1:D6) returns the distinct rows in a new place; =UNIQUE(B2:B6) gives the distinct city list.

Ravindra Bagale's Tip

In Remove Duplicates, many students leave all columns ticked or tick the wrong columns. If the same customer placed two different orders, they are not duplicates! First decide what counts as a duplicate (Order ID? Order ID + Product?), and review with a COUNTIF flag before removing – after Remove Duplicates, you can't get the rows back later.

Practice task

In a list of 20 orders with 4 repeated Order IDs, flag duplicates with COUNTIF, remove them with Remove Duplicates, and confirm the new count with =ROWS(UNIQUE(A2:A21)) (Microsoft 365).

Loading practice tasks...

  1. How many times did P-501 come? (Easy): Count how many times P-501 is in B2:B11.
  2. Does P-506 repeat? (Easy): Check if P-506 appears more than once in B2:B11 (TRUE or FALSE).
  3. First or duplicate? (row 4) (Easy): Is B4 a "Duplicate" or "First"? Count only from B2 down to B4.
  4. First or duplicate? (row 5) (Easy): Is B5 a "Duplicate" or "First"?
  5. Extra visits of Emma (Medium): How many extra (repeat) rows does P-502 have?
  6. Number of different patients (Medium): How many different Patient IDs are in B2:B11?
  7. List of patients (spill) (Medium): Get the list of different Patient IDs from B2:B11.
  8. List of cities (spill) (Medium): Get the list of different cities from D2:D11.
  9. How many duplicate rows? (Hard): How many rows are repeats? (all rows minus different patients)
  10. One row per patient (spill) (Hard): Get the different rows of B2:D11 (3 columns).
  11. Is the last visit a repeat? (Hard): Is B11 a "Duplicate" or "First"?

Quick revision cards

Three standalone cards. Each one explains the idea with its own example. Scan the QR to open this lesson.

Revision card 1: What is Duplicates?
Card 1: What is Duplicates? · Download PNG
Revision card 2: Tiny example — Duplicates
Card 2: Tiny example — Duplicates · Download PNG
Revision card 3: Checklist — Duplicates
Card 3: Checklist — Duplicates · Download PNG