Count in excel with duplicates

Count unique values among duplicates

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 More…Less

Let’s say you want to find out how many unique values exist in a range that contains duplicate values. For example, if a column contains:

  • The values 5, 6, 7, and 6, the result is three unique values — 5 , 6 and 7.

  • The values «Bradley», «Doyle», «Doyle», «Doyle», the result is two unique values — «Bradley» and «Doyle».

There are several ways to count unique values among duplicates.

You can use the Advanced Filter dialog box to extract the unique values from a column of data and paste them to a new location. Then you can use the ROWS function to count the number of items in the new range.

  1. Select the range of cells, or make sure the active cell is in a table.

    Make sure the range of cells has a column heading.

  2. On the Data tab, in the Sort & Filter group, click Advanced.

    The Advanced Filter dialog box appears.

  3. Click Copy to another location.

  4. In the Copy to box, enter a cell reference.

    Alternatively, click Collapse Dialog Button image to temporarily hide the dialog box, select a cell on the worksheet, and then press Expand Dialog Button image.

  5. Select the Unique records only check box, and click OK.

    The unique values from the selected range are copied to the new location beginning with the cell you specified in the Copy to box.

  6. In the blank cell below the last cell in the range, enter the ROWS function. Use the range of unique values that you just copied as the argument, excluding the column heading. For example, if the range of unique values is B2:B45, you enter =ROWS(B2:B45).

Use a combination of the IF, SUM, FREQUENCY, MATCH, and LEN functions to do this task:

  • Assign a value of 1 to each true condition by using the IF function.

  • Add the total by using the SUM function.

  • Count the number of unique values by using the FREQUENCY function. The FREQUENCY function ignores text and zero values. For the first occurrence of a specific value, this function returns a number equal to the number of occurrences of that value. For each occurrence of that same value after the first, this function returns a zero.

  • Return the position of a text value in a range by using the MATCH function. This value returned is then used as an argument to the FREQUENCY function so that the corresponding text values can be evaluated.

  • Find blank cells by using the LEN function. Blank cells have a length of 0.

Examples of nested functions to count the number of unique values among duplicates

Notes: 

  • The formulas in this example must be entered as array formulas. If you have a current version of Microsoft 365, then you can simply enter the formula in the top-left-cell of the output range, then press ENTER to confirm the formula as a dynamic array formula. Otherwise, the formula must be entered as a legacy array formula by first selecting the output range, entering the formula in the top-left-cell of the output range, and then pressing CTRL+SHIFT+ENTER to confirm it. Excel inserts curly brackets at the beginning and end of the formula for you. For more information on array formulas, see Guidelines and examples of array formulas.

  • To see a function evaluated step by step, select the cell containing the formula, and then on the Formulas tab, in the Formula Auditing group, click Evaluate Formula.

  • The FREQUENCY function calculates how often values occur within a range of values, and then returns a vertical array of numbers. For example, use FREQUENCY to count the number of test scores that fall within ranges of scores. Because this function returns an array, it must be entered as an array formula.

  • The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range. For example, if the range A1:A3 contains the values 5, 25, and 38, the formula =MATCH(25,A1:A3,0) returns the number 2, because 25 is the second item in the range.

  • The LEN function returns the number of characters in a text string.

  • The SUM function adds all the numbers that you specify as arguments. Each argument can be a range, a cell reference, an array, a constant, a formula, or the result from another function. For example, SUM(A1:A5) adds all the numbers that are contained in cells A1 through A5.

  • The IF function returns one value if a condition you specify evaluates to TRUE, and another value if that condition evaluates to FALSE.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

See Also

Filter for unique values or remove duplicate values

Need more help?

I have a list of postcodes that includes duplicates. I would like to find out how many instances of each postcode there are.

For example I would like this:

GL15
GL15
GL15
GL16
GL17
GL17
GL17

…to become this:

GL15 3
GL15 3
GL15 3
GL16 1
GL17 2
GL17 2

…or ideally this:

GL15 3
GL16 1
GL17 3

Thanks!

asked Jul 29, 2011 at 15:31

Mr_Chimp's user avatar

4

I don’t know if it’s entirely possible to do your ideal pattern. But I found a way to do your first way: CountIF

+-------+-------------------+
|   A   |         B         |
+-------+-------------------+
| GL15  | =COUNTIF(A:A, A1) |
+-------+-------------------+
| GL15  | =COUNTIF(A:A, A2) |
+-------+-------------------+
| GL15  | =COUNTIF(A:A, A3) |
+-------+-------------------+
| GL16  | =COUNTIF(A:A, A4) |
+-------+-------------------+
| GL17  | =COUNTIF(A:A, A5) |
+-------+-------------------+
| GL17  | =COUNTIF(A:A, A6) |
+-------+-------------------+

answered Jul 29, 2011 at 15:48

Corey Ogburn's user avatar

Corey OgburnCorey Ogburn

23.8k31 gold badges112 silver badges186 bronze badges

This can be done using pivot tables.
See this youtube video for a walkthrough: Quickly Count Duplicates in Excel List With Pivot Table.

To count the number of times each item is duplicated in an
Excel list, you can use a pivot table, instead of manually creating a list with formulas.

brasofilo's user avatar

brasofilo

25.3k15 gold badges91 silver badges178 bronze badges

answered Nov 28, 2012 at 22:10

Scott's user avatar

ScottScott

2312 silver badges2 bronze badges

0

  1. Highlight the column with the name
  2. Data > Pivot Table and Pivot Chart
  3. Next, Next layout
  4. drag the column title to the row section
  5. drag it again to the data section
  6. Ok > Finish

Mansfield's user avatar

Mansfield

14.2k18 gold badges79 silver badges112 bronze badges

answered Jul 9, 2013 at 18:52

soho's user avatar

sohosoho

1111 silver badge2 bronze badges

1

You can achieve your result in two steps. First, create a list of unique entries using Advanced Filter… from the pull down Filter menu. To do so, you have to add a name of the column to be sorted out. It is necessary, otherwise Excel will treat first row as a name rather than an entry. Highlight column that you want to filter (A in the example below), click the filter icon and chose ‘Advanced Filter…’. That will bring up a window where you can select an option to «Copy to another location». Choose that one, as you will need your original list to do counts (in my example I will choose C:C). Also, select «Unique record only». That will give you a list of unique entries. Then you can count their frequencies using =COUNTIF() command. See screedshots for details.

Hope this helps!

  +--------+-------+--------+-------------------+
  |   A    |   B   |   C    |         D         |
  +--------+-------+--------+-------------------+
1 | ToSort |       | ToSort |                   |
  +--------+-------+--------+-------------------+
2 |  GL15  |       | GL15   | =COUNTIF(A:A, C2) |
  +--------+-------+--------+-------------------+
3 |  GL15  |       | GL16   | =COUNTIF(A:A, C3) |
  +--------+-------+--------+-------------------+
4 |  GL15  |       | GL17   | =COUNTIF(A:A, C4) |
  +--------+-------+--------+-------------------+
5 |  GL16  |       |        |                   |
  +--------+-------+--------+-------------------+
6 |  GL17  |       |        |                   |
  +--------+-------+--------+-------------------+
7 |  GL17  |       |        |                   |
  +--------+-------+--------+-------------------+

Step 1Step 2Step 3

answered Feb 23, 2016 at 14:04

Justyna's user avatar

JustynaJustyna

7332 gold badges10 silver badges25 bronze badges

Say A:A contains the post codes, you could add a B column and put a 1 in each cell. In C1, put =SUMIF(A:A, A1, B:B) and Drag it down your sheet. That would give you the first desired result listed in your question.

EDIT:
As Corey pointed out, you can just use COUNTIF(A:A, A1). As I mentioned in the comments you can copy paste special the row with formulas to hard code the counts, the select column A and click remove duplicates (entire row) to get your ideal result.

answered Jul 29, 2011 at 15:42

Gaijinhunter's user avatar

GaijinhunterGaijinhunter

14.5k4 gold badges50 silver badges57 bronze badges

5

If you are not looking for Excel formula, Its easy from the Menu

Data Menu —> Remove Duplicates would alert, if there are no duplicates

Also, if you see the count and reduced after removing duplicates…

answered Jul 3, 2014 at 16:33

HydTechie's user avatar

HydTechieHydTechie

77710 silver badges17 bronze badges

Step 1: Select top cell of the data

Step 2 : Select Data > Sort.

Step 3 : Select Data >Subtotal

Step 4 : Change use function to «count» and click OK.

Step 5 : Collapse to 2

answered Dec 18, 2014 at 9:10

ziad123's user avatar

If you perhaps also want to eliminate all of the duplicates and keep only a single one of each

Change the formula =COUNTIF(A:A,A2) to =COUNIF($A$2:A2,A2) and drag the formula down.
Then autofilter for anything greater than 1 and you can delete them.

answered Jul 3, 2014 at 16:41

datatoo's user avatar

datatoodatatoo

2,0192 gold badges21 silver badges28 bronze badges

Let excel do the work.

  1. Select column
  2. Select Data tab
  3. Select Subtotal, then «count»
  4. DONE

Adds it up for you and puts total

Trinidad Count  99
    Trinidad Colorado
    Trinidad Colorado
    Trinidad Colorado
    Trinidad Colorado
    Trinidad Colorado
    Trinidad Colorado
Trinidad Colorado Count 6
    Trinidad.
    Trinidad.
Trinidad. Count 2
    winnemucca
    Winnemucca
    Winnemucca
    Winnemucca
    Winnemucca
    winnemucca
    Winnemucca
    Winnemucca
    Winnemucca
    winnemucca
    Winnemucca
    Winnemucca
    Winnemucca
    Winnemucca
winnemucca Count    14

Matt's user avatar

Matt

44.3k8 gold badges77 silver badges115 bronze badges

answered Aug 22, 2014 at 15:59

Dave's user avatar

EXPLANATION

This tutorial shows how to count duplicate values in a range, using an Excel formula and VBA.

The Excel formula uses the COUNTIF formula to count the number of duplicate values in a range. Enter the range from which you want to count the number of duplicate values into the first component of the COUNTIF function. The value for which you want to count the number of occurrences from the selected range would be the criteria of the COUNTIF function.

This tutorial shows two VBA methods that can be applied to count duplicate values in a range. The first VBA method uses the Formula property (in A1-style) with the same formula that is used in the Excel method.
The second VBA method uses the COUNT function to return the number of occurrences that a value is repeated in a specified range.

FORMULA
=COUNTIF(range, dup_value)

ARGUMENTS
range: Range of cells to test for duplicate values.
dup_value: The value to check for duplicates in the specified range.

Counting duplicate values is a subject that begs definition. What constitutes a duplicate? Within Excel, you can have duplicate values within the same column or you can have duplicate records — a row where every value in the record is repeated.

In this article, we’ll focus on duplicate values within the same column. Once you start counting duplicates, you’ll often discover that you need more. For instance, you might need the opposite — how many unique values are in the column.

There are several ways to count duplicate values and unique values. You can work with most any dataset or download the .xlsx or .xls demonstration file (although specific instructions for the .xls format aren’t included in this article). To read about finding (as opposed to counting) duplicates in Excel, check out my previous article, “How to find duplicates in Excel.”

LEARN MORE: Office 365 Consumer pricing and features

Use COUNTIF()

Figure A shows a COUNTIF() function that gets the job done:

COUNTIF(B:B,B2)

Figure A

COUNTIF() counts duplicate species.

We’re not counting the number of actual duplicates but rather the number of times the value occurs within the given range. If we were counting strictly duplicates, we wouldn’t include the first occurrence of the value.

As you can see, the function returns the correct count, and it’s a quick fix. The main problem with this structure is the B:B reference. It’s great if you add and delete records, but it’ll also evaluate non-contiguous values. If you enter one of the values below to the dataset, the function will add it to the count, as shown in Figure B, even if it’s not in the actual data range.

Figure B

The reference evaluates non-contiguous values.

Removing the duplicates from view

The COUNTIF() is adequate, but you might want a list of unique values rather than the full dataset. In this case, you can use a PivotTable, as shown in Figure C. To create this view, do the following:

  1. Click a Species value (any cell in B2:B5).
  2. Click the Insert tab and then click PivotTable in the Tables group.
  3. Accept all the default values in the resulting dialog — simply click OK.
  4. In the PivotTable Fields list (to the right), drag the Species field to the Row Labels and the Values sections.

Figure C

Dragging the same to both sections forces a unique count.

Using Subtotal

One of the first two solutions will probably satisfy most situations, but you could also use Excel’s Subtotal feature, which evaluates data by groups. However, it’s not as convenient, because you’ll have to sort the data first. If that’s not a problem, or it’s what you’re doing anyway, you might want to consider using the Subtotal feature:

  1. First, sort the data by clicking inside the column you want to sort. Then, click Sort & Filter in the Editing group (on the Home tab), and choose Sort A To Z from the drop-down list.
  2. With the data sorted, click the Data tab.
  3. In the Outline group, click Subtotal.
  4. In the resulting dialog, set the parameters for your data. In this case, select the Species field and specify the Count function (Figure D).
    Figure D
  5. Click OK.

This feature will insert a subtotaling row below each group. In this case, it also displays an optional grand total for the column ( Figure E).

Figure E

There’s now a subtotaling row below each group.

Counting unique values

The flip side of counting duplicates might be to count the number of unique values. The traditional method is to use the SUMPRODUCT() function. This solution has been around for a long time, and I can’t take credit for it. To the best of my knowledge, Excel still doesn’t have a built-in function for counting unique values. When counting unique values, use the following expression:

=SUMPRODUCT((range<>””)/COUNTIF(range,range&””))

Figure F shows this function at work in our example data… sort of.

Figure F

Return the number of unique values in a column.

As you can see, the function

=SUMPRODUCT((B:B<>””)/COUNTIF(B:B,B:B&””))

returns 4 and there are 3 unique values. The problem is the column reference. There’s nothing wrong, but there are actually 4 unique values in column B, because the function evaluates the entire column — including the string Species in B1. If you can delete the header text, this expression works. If you can’t, subtract 1 from the final count, as shown in Figure G.

Figure G

Refining the expression.

Duplicates and more

Within the context of duplicates, definitions aren’t the same. In this case, we used a function and two built-in features to count the number of times a value is repeated in the same range. Then, we used an expression to return the number of unique values in the same range.

Send me your question about Office

I answer readers’ questions when I can, but there’s no guarantee. When contacting me, be as specific as possible: For instance, “Please troubleshoot my workbook and fix what’s wrong” probably won’t get a response, but “Can you tell me why this formula isn’t returning the expected results?” might. I’m not reimbursed by TechRepublic for my time or expertise, nor do I ask for a fee from readers. You can contact me at susansalesharkins@gmail.com.

Affiliate disclosure: TechRepublic may earn a commission from the products and services featured on this page.

This post will guide you how to count for duplicates in Excel. You will learn how to count the instances of each duplicate value in a column.  You can use the COUNTIF function to count the duplicate values in a column in Excel.

If you have a list of data that contain duplicated values in a column, and you may want to know how many duplicates are there for each values. You can use the COUNTIF function to count the total number of cells within a selected range of cells which match a given criteria. The syntax of the COUNTIF function is as below:

= COUNTIF (range, criteria)
  • Range -This is a required argument.  The range of cells that you want to apply the criteria to count
  • Criteria – This is a required argument.  The criteria used to define which cells are counted

Table of Contents

  • Count Duplicates values in a column
  • Duplicates value checking
    • Related Functions
    •  Related Posts

Count Duplicates values in a column

Assuming that you want to count duplicates in column B for each of those values, you can create an excel formula based on the COUNTIF function as follows:

=COUNTIF($B$2:$B$6, B2)

count duiplicates1

You need to provide an absolute cell reference for the range of cells that you need to count all the duplicates in. so the range value can be set as: $B$2:$B$6.

If you need to count the total number of duplicates for two or more values in a column, for example, you maybe need to count how many times two sets of values are duplicated within a cell range. You just need to add one more COUNTIF formula, such as:

=COUNTIF(B2:B6,B2) + COUNTIF(B2:B6,B4)

count duiplicates2

Duplicates value checking

If you want to check if the value in a cell is duplicated. If duplicated, then returns duplicate message, otherwise, returns unique message. You can create the below formula based on the IF function and COUNTIF function to check duplicates in a range of cells B2:B6.

=IF(COUNTIF($B$2:$B$6,B2)>1, "Duplicate", "Unique")

count duiplicates3


  • Excel COUNTIF function
    The Excel COUNTIF function will count the number of cells in a range that meet a given criteria. This function can be used to count the different kinds of cells with number, date, text values, blank, non-blanks, or containing specific characters.etc.= COUNTIF (range, criteria)…
  • Excel IF function
    The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE. The IF function is a build-in function in Microsoft Excel and it is categorized as a Logical Function.The syntax of the IF function is as below:= IF (condition, [true_value], [false_value])….

  • Count the number of words in a cell
    If you want to count the number of words in a single cell, you can create an excel formula based on the IF function, the LEN function, the TRIM function and the SUBSTITUTE function. ..
  • Get the First Match in Two Excel Ranges
    If you want to find the first match between two excel ranges, you can use a combination of the INDEX function, the MATCH function and COUNTIF function to create a new formula….
  •  Extract a List of Unique Values from a Column Range
    If you want to extract a list of unique items from a column or range, you can use a combination of the IFERROR function, the INDEX function, the MATCH function and the COUNTIF function to create an array formula….

Понравилась статья? Поделить с друзьями:
  • Count in excel but not duplicates
  • Count in between dates excel
  • Count if with and in excel
  • Count if true excel
  • Count if this and this excel