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

5. Data Cleaning A–Z

Excel

5.1 Duplicates

1. Decide whether a repeated value means a repeated record

Imagine a student film club preparing a reimbursement tracker. The members buy equipment through retailers such as Amazon and keep their own order-line export for practice. The same order appears beside a monitor on one row and a cable on another. Those are two real items within one order. A third row repeats the monitor, its line number and its original amount. That one might have arrived when a volunteer imported the same batch twice. One order identity can have multiple line identities, so a rule for repeated orders would raise more cases than the problem actually contains.

There is also a tripod line with a quoted value and a later accepted value. The two rows have the same line key but different amounts and states. This is a conflict or a revision, depending on the source record. Treat it differently from an identical replay until you confirm which record should lead the report. The values and records here are fictional teaching data. They describe the college's ledger, not a retailer's internal data.

Define the record first. Check the right identity fields, count how often each key appears, and decide what approvals determine which row belongs in each report. Keep a raw copy before changing anything.

Order O-501 line 1 appears twice and is a duplicate candidate. O-501 line 2 has a different line number and belongs as a separate record.
Two fields identify a line in this workbook. A repeated order alone does not tell you which line repeated.

Distinguish three useful kinds of repeat

  • Same display field. Two people can share a first name or two items can share a price. A repeated value in one column does not make two records duplicates when that column is not their identity.
  • Same key, same relevant fields. Two copies of the same order line, quantity, amount and state can suggest a replay. Confirm the export or import history before choosing the accepted copy.
  • Same key, different relevant fields. A later revision, mistaken key or missing part of the identity may explain the difference. Inspect all candidates and document the retention rule.

If you count repeated patient IDs in a teaching appointment log, you can find patients with multiple visits. That is useful and does not imply the visits should disappear. If your records are individual appointments, an issued appointment ID or another confirmed key identifies the row. The cleaning rule follows the meaning of the table, not which heading is easiest to click.

Make the source identities portable

Keep the original input file and work in a separate practice sheet. Assign a stable Source Row ID if the file lacks one. Use a fixed added value such as D01 or a combination of file batch and initial line number. A changing Excel row number describes the current position after a sort. It is not the original identity unless you captured the earlier position. A source reference makes it possible to find both a kept row and a held one after sorting, filtering or copying.

Decide whether identity values are stored as text or number. An ID such as 0007 may have to remain text so its leading zeros survive. If Excel already turned two distinct IDs into the same numeric value because of type conversion or precision, an ordinary deduplication rule cannot reconstruct the originals. Reimport the correct source with the intended type. Preserve the written characters when those characters define the key.

2. Choose a non-destructive check before you remove a row

Use a highlight to locate repeated values quickly

Conditional Formatting > Duplicate Values can show repeated cells in a selected identifier column. Both copies are useful to the reviewer. To test a combination of fields, create a helper count or a deliberately safe combined key for the exercise. An ID containing separator characters could create an ambiguous concatenation. COUNTIFS compares the component ranges individually, which is easier to understand for our simple composite key.

The highlight gives you a visual pattern. It does not decide which row to keep, move any rows or change the data type. Two completed line records can have the same state and still both belong. Use a colour only on the cells that answer the actual repeat question. Add a count or separate text review result if someone needs to filter a review list or reproduce the result without seeing colour.

Decide whether to count the whole group or the rows seen so far

A count over the whole sample tells you all the records that share the selected identity. In the working dataset, every record whose key occurs twice will show 2. A count over a range from the first row to the current row tells you whether the key has appeared earlier in the current order. The first shows 1, the next shows 2. The expanding count is useful for identifying later appearances. It is not evidence that earlier or later is the one that should be kept.

For a single ID column, the familiar formulas are =COUNTIF($B$2:$B$9,B2) for the full sample and =COUNTIF($B$2:B2,B2) for the prefix. The dollar sign at the first anchor keeps the starting reference fixed. The endpoint moves down with the checked row for the prefix. Read the actual result on the first and second occurrence to understand why the formulas answer different questions.

When ID text values can contain asterisks or question marks, provide a literal check or escape those characters in functions that interpret wildcards. COUNTIF and COUNTIFS can also ignore case in practice. For fields where case or punctuation is part of identity, use a deliberate exact comparison and a controlled fixture. Our lab keys are ordinary uppercase prefixes and numeric lines, so the simple count applies to the stated sample. It is not a universal policy for every ID format.

Filter or calculate a list separately

Excel's Advanced Filter has a Unique records only option on desktop editions that support it. An in-place filter hides values from the current view and can be cleared. A copied list of unique records gives readers a separate result. Test whether its comparison includes the columns you intended. Colouring or filtering repeated cells is reversible and helps you inspect what would be removed before preparing an approved output.

On Excel versions supporting dynamic arrays, =UNIQUE(B2:C9) returns one row for each distinct pair without editing the input. If you supply FALSE,TRUE as the optional by-column and exactly-once arguments, UNIQUE returns only keys occurring once. This is a different question from keeping one occurrence from every group. Also notice that including a unique Source Row ID in the input can make every row distinct, even when a subset of fields repeats.

3. Lab. Find replays, conflicting revisions and legitimate lines

Goal. Build an audit that accounts for every source line. Enter the A1:F9 table into Raw, then duplicate to Work. The source ID is text, Line is numeric, and Amount is signed INR. Do not remove any row in this lab. Our instructions will supply the disposition and reasons once the candidates are visible.

Eight fictional equipment ledger rows
Source rowOrder IDLineItemAmount (INR)State
D01O-5011Monitor1450Completed
D02O-5012Cable350Completed
D03O-5011Monitor1450Completed
D04O-5021Tripod780Pending
D05O-5021Tripod820Completed
D06O-5031Battery650Completed
D07O-5041Battery650Completed
D08O-5051Refund-120Refunded

Count the group, compare fields and reconcile a view

  1. Count the source and check the real key

    There are eight rows and five distinct Order IDs. Using the combination of Order and Line, there are six distinct line keys. Calculate the raw signed total with =SUM(E2:E9) and expect 6030. Before writing any retention rule, point to the legitimate O-501 line 2 and the independent Battery orders.

  2. Flag every candidate and its appearance order

    Put Key group size, Seen so far and Matching supplied fields in G1:I1. Enter the three formulas below and fill them through row 9. G should be 2 for D01, D03, D04 and D05. H should be 2 only for D03 and D05. I is 2 on D01 and D03, because their other supplied data agree, while I is 1 on each tripod row.

  3. Classify with source evidence

    For the exercise you have confirmation D03 is a replay of D01. D05 is the approved tripod revision, and D04 is its earlier version. Put Disposition in J1. Mark D03 as Replay, D04 as Superseded and all other rows Publish. Put the reason beside each decision. The later occurrence rule correctly found D05 as a repeated key, but it was exactly the record we needed to keep.

  4. Check counts and known amount by disposition

    Use COUNTIF to count the three J categories. Rows reconcile as 6 Publish, 1 Replay and 1 Superseded. Use SUMIF over J with E as the sum range. Publish totals 3800, Replay 1450 and Superseded 780. These add to 6030. Check the kept source IDs, the O-501 line 2 and the signed refund independently.

  5. Show how a different policy would change the result

    On a copy, work out what happens if you always keep the first occurrence of the key. D04 at 780 would replace the approved D05 at 820. Both results could still have six rows. The signed publish total under that wrong policy would be 3760. A correct row count alone cannot confirm that the intended versions were kept.

G2 =COUNTIFS($B$2:$B$9,B2,$C$2:$C$9,C2)
H2 =COUNTIFS($B$2:B2,B2,$C$2:C2,C2)
I2 =COUNTIFS($B$2:$B$9,B2,$C$2:$C$9,C2,$D$2:$D$9,D2,$E$2:$E$9,E2,$F$2:$F$9,F2)

The I formula checks the supplied fields in the sample. A real source can have an actual revision timestamp, currency or special notes that should enter the comparison. Match all relevant fields and confirm the intended key. If a candidate appears separately in a second authorised source, be careful about treating the two records as interchangeable. Two equal amounts can be different obligations and duplicate-looking rows can be evidence of an upstream problem.

Compare two independent tests for the candidate group

Try an explicit group count and a matching-field count for the same source row. If G is 2 and I is 1, the row has a key mate that differs somewhere among the listed fields. This is a straightforward signal to compare both records. If G and I are both 2, every checked field matches the other member. You still need the source rule for whether an identical-looking event can occur twice legitimately. A vendor may send two separate transactions with the same descriptions and amounts. Only the business key distinguishes them.

If you have a current Excel edition that offers UNIQUE, in a spare area use =UNIQUE(B2:C9). Expect six key pairs. =UNIQUE(B2:C9,FALSE,TRUE) instead produces four whose keys occur exactly once. Neither result carries the reasons for the accepted versions or the correct amount when a key appears twice. The dynamic output is a set of keys, and our disposition columns identify the actual records the report should use.

Use a second summary as a sanity check, not as a substitute for reading source IDs. For this ledger an order-only distinct count is five; a line-key count is six. Someone cleaning the table can know that at least one valid order has multiple lines. If the approved report has a total by item, preserve both independent batteries even though they have the same amount. Grouping by item to sum its costs answers another question from deciding which transactions are duplicates.

4. Set a retention rule before using a command

Write a rule that covers conflicting records

Common policies include the earliest confirmed receipt, the most recent approved version or checking both sources in an unresolved conflict. Avoid a rule such as keep latest if the source does not establish which version is approved. A later edited or exported row may not be more accurate. Work with an authoritative version or review status. Save the evidence for each exception in a separate field. That makes the chosen row explainable when someone follows up later.

Excel's Remove Duplicates keeps the first qualifying row for a comparison group in the selected list. Decide your intended ordering first. Make a disposable copy, order complete records with a documented tie-break and then inspect the actual kept IDs. The command does not merge non-key data such as notes, versions or quantities from rows that are removed. If you intend to preserve a note, copy or consolidate it separately after review rather than expecting the command to combine fields for you.

Microsoft also points out that displayed values can matter when comparing duplicates. It uses the example of one date serial with two different date displays. Be consistent about the comparison fields, underlying types and applicable formats before relying on a removal result. If a timestamp's minutes are important but you only see the day in the source, display or extract the relevant precision explicitly and verify the key. Our next lab uses comparable text times to make the chosen key obvious.

Recall. The earliest entry has the same key as the latest approved row, but a different amount. Would a first-occurrence command use the approved record automatically? What order or separate review would you create to make the result deliberate?

5. Lab. Test a documented first-row policy on a copy

Goal. Prepare one published record per counter and time in a small reservation sheet, while preserving accepted and held evidence. The sample describes a single day, 23 November 2026. A desk can use several time slots on the same day. The key for this same-day fixture is Counter plus Slot. A real multi-day sheet should include the calendar date too.

Reservation records with a known version and one missing key
Source rowCounterSlotVersionReserved boxes
W01Desk A09:00112
W02Desk A09:00215
W03Desk B09:00112
W04Desk B09:00112
W05Desk B10:0015
W06Desk C12
  1. Check the original order and known one-day key. Use a separate workbook or sheet copy of the fictional data. In this sample enter slot values with one consistent typed convention, for example format Slot as text before typing the exact 09:00 and 10:00 labels. Use numeric box counts and version values. Count six rows and 58 boxes across all versions. That sum describes raw inputs including extras. It is not a total of confirmed unique reservations.
  2. Hold the missing key outside the publish candidate list. Keep W06 in the working sheet with a reason such as Missing time. Copy the five other whole records and their headers into an isolated practice area. Do not let a blank key stand in for a valid shared time. Inspect the count of five rows and the source IDs. Choose a blank output area so adjacent unrelated records cannot become detached.
  3. Apply the approved order for this exercise. Confirm that W02 is Desk A's accepted version. W03 and W04 are equivalent copies confirmed by the practice source. Keep the earlier source ID W03. In the copied candidate list sort whole records first by Version, largest to smallest, then by Source row, smallest to largest. This puts W02 before W01 and W03 before W04. The sort only changes the copied list, where you will test the first-occurrence behavior.
  4. Remove duplicates only in the disposable list copy. Select the whole candidate list, including all fields in each row. Open Data > Remove Duplicates in a compatible edition. Mark that the range has headers. Select only Counter and Slot as comparison columns. Do not include Source row or Version in the key. Keep the permanent input and working records separate. Check the resulting IDs and expected count, rather than accepting the dialog's count alone.
  5. Explain the report balance. Expect W02, W03 and W05 to remain, for 32 boxes. W01 accounts for 12 earlier boxes and W04 for 12 replayed. W06 was held before the removal and accounts for 2. Those four classified sums reconcile to the original 58. Use one list of kept IDs and one list of excluded IDs. A person can check what happened to every input.

If the exercise keeps the wrong version, return to your test copy and inspect ordering and selected key columns. If all fields including Source row are selected, each row is distinct because that field is unique. If only Counter is selected, Desk B's separate 10:00 reservation could disappear. Check the candidate keyed value at the moment you click the dialog. An unintended setting can yield a tidy but inaccurate result.

Desk A at 09:00 has 12 boxes in version one and 15 in approved version two. Ordering the approved version before the other row makes the first-occurrence test retain 15.
First is a position. Approved is a business decision. Set the order deliberately when the command keeps the first row.

Test the same retention logic without deleting rows

A nondestructive review can filter the original Work sheet on a separate Publish column or use a formula with the reviewed set of IDs. This keeps the underlying alternatives available and makes it easier to see where a row went. If the current outputs should be sent separately, create a copy of the accepted data and keep the reconciliation in the working file. A visible filter is not a constraint on somebody else's report if they choose to clear it.

In a version with dynamic array support, a simple FILTER result can select records whose disposition is Publish. Give the no-match state an explanation. The filter result should be recalculated after the reviewed source status changes. Avoid silently treating the first occurrence as approved inside the formula if the group still has an unresolved conflict. Existing hold statuses are evidence, even when the current number of accepted rows is zero.

6. Maintain the rule across imports and platforms

Check exact matching when keys include special characters

Suppose a different catalogue uses the literal ID AB? as one item and AB1 as another. A search using question mark as a wildcard may match the latter even though those IDs are different. For a one-column literal case-sensitive audit, =SUMPRODUCT(--EXACT(B2,$B$2:$B$9)) compares the actual characters in the selected block. Test entries that differ by a character, case and a trailing space. If the source says case variation should be treated as the same code, build that normalisation on purpose and preserve the raw form.

For a case-sensitive composite key in this lesson's structure, an optional test is =SUMPRODUCT(--EXACT(B2,$B$2:$B$9),--(C2=$C$2:$C$9)). The arrays contain matches on the same positions. The first expression checks characters for the order key. The second compares line numbers. Both must match on the same row to contribute one. Use a short confirmed range so the test remains inspectable. Check missing key fields before making decisions from either count.

Be explicit about which row survives in Power Query

For recurring exports, a query can preserve the raw inputs and reproduce reviewed processing. The Power Query function Table.Distinct removes duplicates on chosen fields. Microsoft cautions that query optimisation and source execution can make it unsafe to assume the first input row will always survive. If retained details matter, design an explicit grouping and priority step or a documented, tested method for predictable removal. The worksheet behavior from the lab does not automatically apply to every query.

A supported transformation can group by the business key, retain exact replay candidates and record versions before producing a final view. Use a small fixture where the first row is intentionally the wrong one, such as the tripod or Desk A. Confirm the saved procedure keeps the approved row after a second refresh. Do not interpret successful query execution as proof of which version it chose. Preserve the exception counts and original evidence alongside the refreshed copy.

Check the Excel commands available in the edition the team is using. Microsoft documents several unique/value removal methods, and the desktop manager and Advanced Filter workflow can look different or be unavailable online. A helper formula and source-ID reconciliation work even when a particular menu route is absent. Use the exact same records when comparing behavior so you can identify an edition difference without confusing it with a data change.

Use an acceptance check that another person can execute

  • Confirm one current-version and one replay decision by their source IDs.
  • Confirm a legitimate second line with an earlier shared Order ID still remains.
  • Check that the accepted and held line counts add back to every input before release.
  • Check both sums and signs. A different retained version can change value without changing the count.
  • Compare an import with a changed order of rows, if the workflow needs approval-based results to stay consistent.

Check your chosen sort against a conflicting equal-version example

In a copy of the reservation practice table, imagine that two Desk A rows both store version 2, but one says 15 boxes and the other says 16. The retained first row is now determined by the source-row tie order. Sorting by version no longer decides whether either is the accepted value. A good workbook should label that group Hold for confirmation unless an authority defines how to choose. An exact replay with the same version and amount is easier to resolve than a conflict within the same version. Do not use the command to settle a disputed source fact.

Record the approval field separately. If the source owner confirms the 16-box record, mark its actual row ID and review reason. A workflow based on confirmed records can assemble the publish view from the review decisions. A deterministic tie-break is helpful for identical approved copies, such as W03 and W04. It is not a substitute for inspecting different business facts. Test this distinction with one identical pair and one conflicting pair. Both pairs should remain visible in the source evidence, with different recorded reasons.

Test cases where generated keys can collide

Joining columns can make a combined key easy to display, provided the join is unambiguous. For instance, appending 3 to text AB12 without a separator gives AB123. Appending 23 to AB1 creates the same text. If both pairs can exist, that key cannot tell them apart. A separator helps if it cannot already occur in one of the fields, or if it can be escaped unambiguously. A composite count across separate columns avoids this collision for the practice range.

Try two worksheet rows with those pairs. Put AB12 and AB1 in B2 and B3, and 3 and 23 in C2 and C3. In a spare column use =B2&C2, then copy it down. Both labels are AB123. An exact two-field comparison sees different rows. Compare =COUNTIFS($B$2:$B$3,B2,$C$2:$C$3,C2) with a simple count of the generated label. The former gives 1 and the latter gives 2 for either row. This establishes why your choice of key format affects the apparent duplicate rate.

Include a blank-key example too. If Order ID is blank and Line is 1, the key count could still group it with another incomplete row. Grouping two incomplete values does not supply evidence about real identity. Give both a sufficient review status and keep them out of irreversible work. Once the missing ID is verified, re-run the group check with that exact typed value rather than guessing from the prior record.

Make the published and source totals easy to reproduce

For the order example use =SUMIF(J2:J9,"Publish",E2:E9) to calculate 3800. In two neighbouring cells use the same formula with Replay and Superseded as criteria, obtaining 1450 and 780. The three subtotals are made from the same numeric amount range and the same beginning and ending row. The criteria range and the amount range must be aligned. If the amount starts at E3 while the decisions start at J2, the formula no longer represents the same records.

Check one nonpublication and one inclusion against the IDs, not just the total. A row can have the exact same amount as another, so a total could match while the wrong record is kept. Our order sample has independent 650-rupee battery purchases. If one disappears and a faulty step copies the other twice, their subtotal may still look plausible. The publication should contain D06 and D07 by its stable identifiers, not two copies of D06. Verify the key and signed balance together.

Decide whether a sum is intended to show raw money, accepted known money or approved actuals after a later adjustment. Those are different scopes even if all amounts use INR. A footer that simply says Total without a scope makes downstream reviewers rely on assumptions. Label it Published signed amount and keep the hold and replay figures beside the internal operating copy. If different units or currencies are present, reconcile them separately.

Check the result after reversing the source order

Use a duplicate copy of the order rows. Reverse their working order by sorting the complete records by Source row, largest first. The full group sizes remain the same. The expanding count now marks a different apparent first occurrence for the replay pair. A disposition tied to an authorised source ID, rather than its current row position, should remain associated with the intended record. The accepted amount still equals 3800 when the reviewed labels move with the records. Recheck the actual publish IDs to prove the sort did not separate the values.

After the test, restore the working copy or discard it. If a refreshed file comes in a different order, use the source's actual stable identifiers and keep the current approval for each record. A dynamically recreated row index from the new file alone may identify a different input. Retain the export version or source transaction key when you need decisions to travel across refreshes.

Keep a short comparison fixture for imported identifiers

In a separate exercise enter text identifiers 0007 and 7. Keep both as text before entry. An exact comparison should distinguish them. If one file contains numeric 7 and simply displays four digits with a number format, examine which identifier the field is intended to hold. The displayed digits are not proof that the original characters survived. Reimport the preserved source if you need exact characters, especially when an identifier has more digits than Excel's numeric precision supports.

Now compare two source dates with the same intended calendar day, one stored as text and one as a true serial. Treat formats and value types as separate decisions. Convert the source date only after confirming its convention and choose one controlled presentation on your duplicate-test copy. Run a known pair through the same process, since Microsoft describes duplicate comparison as affected by what appears in the cell. The more critical the key, the more useful a separate typed helper is for testing it.

When you use an exact helper to preserve differences, record which differences count. A trailing space might be a typo in one field and a deliberate character in another. Build a small input pair with the expected difference and a second pair that should match. Confirm that the result respects both examples before moving from a practice sheet to an authorised process.

Review the site's Remove Duplicates guide for the Data tab workflow. Then use the existing Excel Task Hub for a different dataset. Define the expected identity and retained versions before applying the command.

7. Interview questions with practical answers

How would you find duplicate rows without deleting anything?

Define the row grain and key, preserve raw records, then use a duplicate highlight or a group count. Compare every member of an identified group, and document whether it is a replay, revision or legitimate repeated display field.

Why should a repeated order ID sometimes be retained?

In a line-item table there can be multiple lines under the same order. Use the combined order and line identifiers. Removing duplicates on the order ID alone could discard a real item.

What is the difference between an expanding count and a full-group count?

The expanding formula marks appearances so far and distinguishes the first from later positions. The full comparison reports the group size on every member. Neither decides which version has been approved.

How do you use Remove Duplicates without keeping the wrong version?

Make a disposable copy, sort complete records into documented approved order, then select only the confirmed comparison key. The command keeps the first group member. Verify the actual kept IDs, amounts and legitimate secondary records.

What if the count of retained rows is correct but the total is wrong?

Check which version survived each repeated key and whether values, currencies or signs were changed. In the lab either version choice gives six final rows, yet the wrong tripod version makes the report 40 INR lower.

8. Predict before applying a step

  1. Which field should join Order ID to identify the rows in the first lab?

    Answer and reasoning

    The Line field. One order can contain more than one legitimate item.

  2. What should happen to D05 when it is the second occurrence and the approved revision?

    Answer and reasoning

    Retain it. The later-occurrence flag identifies a group member. The confirmed approval tells you which one belongs.

  3. Does the first-row worksheet removal command combine notes from both rows?

    Answer and reasoning

    No. If you need both notes, preserve or consolidate them deliberately before choosing the published row.

  4. What is the difference between a distinct list and a list of values occurring exactly once?

    Answer and reasoning

    A distinct result includes one representative key from every group. Exactly once omits keys with more than one appearance. That is six keys versus four here.

  5. What should you do if a key field is blank in a reservation sheet?

    Answer and reasoning

    Keep it as a separate review case. A blank cannot establish which legitimate slot the reservation belongs to. Include it in the original reconciliation.

9. Six decisions to remember

  • Define one record

    An order, its line and a customer can have different keys. Choose the right level before comparing data.

  • Count both ways

    A full count finds each candidate. An expanding count distinguishes its order of appearance.

  • Keep the approved version

    Inspect changed fields rather than throwing away a revision because its ID is repeated.

  • Test on a copy

    Remove Duplicates deletes from the selected copy and keeps the first matching row. Verify who came first on purpose.

  • Keep a source trail

    Stable row identifiers connect the accepted line and its alternatives back to their input records.

  • Reconcile more than count

    Confirm values, sums, signs and approved source IDs in the published result.

Microsoft references