Skip to main content

How to count unique values based on another column in Excel?

Author: Xiaoyang Last Modified: 2025-04-09

Count unique values based on criteria example

When working with data in Excel, you might encounter situations where you need to count the number of unique values in one column, grouped by the values in another column. For example, I have two columns data, now, I need count the unique names in column B based on the content of column A as left screenshot shown. This article provides a detailed guide on how to achieve this efficiently, along with optimization tips to enhance performance and accuracy.

Count unique values based on another column


Count unique values based on another column with a formula

If you prefer using formulas, you can use a combination of SUMPRODUCT and COUNTIF functions to count unique values.

1. Enter the following formula into a blank cell where you want to put the result, then drag the fill handle down to get the unique values of the corresponding criteria. See screenshot:

=SUMPRODUCT(($A$2:$A$18=D2)/COUNTIF($B$2:$B$18,$B$2:$B$18&""))

Count unique values based on criteria with a formula

Explanation of the Formula:
  • A2:A18=D3: This part checks if the course in column A is the cell value D3, returning an array of TRUE/FALSE values.
  • COUNTIF(B2:B18,B2:B18&""): This counts the occurrences of each student name in column B.
  • SUMPRODUCT: This function sums the results of the division, effectively counting unique names.

Count unique values based on another column with Kutools for Excel

Streamline your data analysis with Kutools for Excel, a powerful add-in that simplifies complex tasks. If you need to count unique values based on another column, Kutools offers an intuitive and efficient solution.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Itegarate with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

After installing Kutools for Excel, please click "Kutools" > "Merge & Split" > "Advanced Combine Rows" to go to the "Advanced Combine Rows" dialog box.

In the "Advanced Combine Rows" dialog box, please set the following operations:

  1. Click the column name that you want to base your unique count on, here, I will click Course, and then select "Primary Key" from the drop-down list in the "Operation" column;
  2. Then, select the column name you want to count the values, and then select "Count" from the drop-down list in the "Operation" column;
  3. Check "Delete duplicate values" option to count only the unique values;
  4. At last, click OK Button.
  5. specify the options in the dialog box

Result: Kutools will generate a table with the unique counts based on your specified column.
Count unique values based on criteria with kutools

Note: Since Kutools directly modifies the original data, it is essential to back up your data before using Kutools to prevent any unintended changes or loss.

Count unique values based on another column with UNIQUE and FILTER functions

Excel 365 or Excel 2021 and later versions introduces powerful dynamic array functions like UNIQUE and FILTER, which make it easier than ever to count unique values based on another column.

Enter or copy the below formula into a blank cell to put the result, and then drag the formula down to fill it the other cells, see screenshot:

=IFERROR(ROWS(UNIQUE(FILTER($B$2:$B$18,$A$2:$A$18=D2))), 0)

Count unique values based on criteria with a formula in Excel 365

Explanation of the Formula:
  • FILTER($B$2:$B$18, $A$2:$A$18=D2): Filters the values in column B where the corresponding value in column A matches the value in D2.
  • UNIQUE(...): Removes duplicates from the filtered list, keeping only unique values.
  • ROWS(...): Counts the number of rows in the unique list, effectively giving the count of unique values.
  • IFERROR(..., 0): If there’s an error (e.g., no matching values in column A), the formula returns 0 instead of an error.

In summary, counting unique values based on another column in Excel can be achieved through various methods, each suited to different versions and user preferences. By choosing the method that best fits your Excel version and workflow, you can efficiently manage and analyze your data with precision and ease. If you're interested in exploring more Excel tips and tricks, our website offers thousands of tutorials.


Related articles:

How to count the number of unique values in a range in Excel?

How to count unique values in a filtered column in Excel?

How to count same or duplicate values only once in a column?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!