Countif Unique Google Sheets: How to Count Unique Values
In this article
To count unique values in Google Sheets, use the =COUNTUNIQUE(range) function for a simple list, or a combination of =COUNTUNIQUEIFS(range, criteria_range, criterion) for conditional counting. While Google Sheets does not have a single function named "COUNTIF UNIQUE," these tools allow you to isolate distinct entries and count them based on specific rules or across an entire dataset.
What You'll Need
- A Google account with access to Google Sheets.
- A dataset containing duplicate entries that you wish to filter and count.
- Basic familiarity with selecting cell ranges (e.g., A2:A100).
Step-by-Step
Depending on whether you need a total count of unique items or a count of unique items that meet a specific condition, follow the appropriate method below. Note that menu labels and function behaviors may vary slightly depending on your region or account version.
Method 1: Basic Unique Count (The Simple Way)
- Open your Google Sheet and identify the column or range containing the data you want to analyze. For example, if you have a list of customer names in column A from row 2 to row 50, your range is
A2:A50. - Click on the empty cell where you want the result to appear.
- Type the formula:
=COUNTUNIQUE(A2:A50). - Press Enter. Google Sheets will instantly scan the range, ignore any duplicate entries, and return the total number of distinct values.
Method 2: Conditional Unique Count (The "Countif Unique" Way)
If you need to count unique values only if they meet a certain condition (e.g., count unique customers who live in "New York"), use the COUNTUNIQUEIFS function.
- Identify your Count Range (the values you want to count uniquely) and your Criteria Range (the column containing the condition). For example, Column A contains Customer Names and Column B contains Cities.
- Click the cell where you want the result.
- Type the formula using this syntax:
=COUNTUNIQUEIFS(count_range, criteria_range, criterion). - Example: To count unique customers in New York, enter
=COUNTUNIQUEIFS(A2:A50, B2:B50, "New York"). - Press Enter. The formula will look at Column B, find all rows that say "New York," and then count how many unique names appear in Column A for those specific rows.
Method 3: Advanced Unique Count using UNIQUE and COUNTA
For more complex scenarios where you might want to see the list first or use multiple complex filters, you can nest the UNIQUE function inside a COUNTA function.
- Select a cell and type
=UNIQUE(A2:A50). This creates a dynamic list of every unique item in that range. - If you don't want the list but just the number, wrap that formula in
COUNTA. - Type:
=COUNTA(UNIQUE(A2:A50)). - Press Enter.
UNIQUEextracts the distinct values, andCOUNTAcounts how many items are in that resulting array.
Method 4: Unique Count with Multiple Conditions
- When you have more than one condition (e.g., unique customers in "New York" who spent over "$100"), continue adding ranges and criteria to the
COUNTUNIQUEIFSfunction. - Use the syntax:
=COUNTUNIQUEIFS(count_range, criteria_range1, criterion1, criteria_range2, criterion2). - Example:
=COUNTUNIQUEIFS(A2:A50, B2:B50, "New York", C2:C50, ">100"). - Press Enter to get the final count of unique entries meeting all specified criteria.
Common Mistakes
One of the most frequent errors is confusing COUNTUNIQUE with COUNTIF. COUNTIF counts every instance of a value, including duplicates. If "John" appears five times, COUNTIF returns 5, while COUNTUNIQUE returns 1. Another common mistake is mismatched range sizes. In COUNTUNIQUEIFS, the count range and the criteria range must be the exact same size. If your count range is A2:A50 but your criteria range is B2:B100, Google Sheets will return a #VALUE! error because the arrays are not aligned.
Users also often forget to put text criteria in quotation marks. For example, writing =COUNTUNIQUEIFS(A2:A50, B2:B50, New York) without quotes will result in a #NAME? error because the sheet thinks "New York" is a named range rather than a piece of text. Always wrap text strings in double quotes.
Tips
To make your formulas more dynamic, instead of typing "New York" directly into the formula, reference a cell. For example, if you type "New York" into cell E1, your formula becomes =COUNTUNIQUEIFS(A2:A50, B2:B50, E1). This allows you to change the city in cell E1 and see the unique count update automatically without editing the formula itself.
If you are dealing with a massive dataset that grows daily, use open-ended ranges. Instead of A2:A50, use A2:A. This tells Google Sheets to look from row 2 all the way to the bottom of the sheet, ensuring that new data added tomorrow is automatically included in your unique count.
For those who prefer a visual approach over formulas, the Pivot Table tool is an excellent alternative. By inserting a Pivot Table, adding your data to the "Rows" section, and then creating a "Calculated Field" or using the "Count Unique" summarization option (available in certain Google Sheets updates/configurations), you can generate a unique count summary for multiple categories simultaneously.
Troubleshooting
If your formula is not returning the expected result, start with these checks:
- Check for Hidden Spaces: This is the most common cause of incorrect unique counts. "New York" and "New York " (with a trailing space) are treated as two different unique values. To fix this, use the
TRIMfunction on your data or wrap your range inARRAYFORMULA(TRIM(A2:A50)). - Verify Data Types: Ensure that numbers are formatted as numbers and not as text. A cell containing the number 100 formatted as text is different from the number 100 formatted as a digit. Use
Format > Numberto standardize your columns. - Handle Blank Cells:
COUNTUNIQUEmay count a blank cell as a unique value. If your range includes empty cells and your count is one higher than expected, you can use aFILTERfunction to remove blanks first:=COUNTUNIQUE(FILTER(A2:A, A2:A <> "")). - Check for #VALUE! Errors: As mentioned, this usually means your ranges are different lengths. Double-check that both the count range and the criteria range start and end on the same row numbers.
- Check for #NAME? Errors: This usually indicates a typo in the function name or missing quotation marks around a text criterion.
Frequently Asked Questions
Does COUNTUNIQUE ignore case sensitivity?
Yes, COUNTUNIQUE in Google Sheets is generally case-insensitive. "Apple" and "apple" are treated as the same value and will be counted as one unique entry.
Can I count unique values across multiple columns?
Yes. You can provide multiple ranges within the function, such as =COUNTUNIQUE(A2:A50, C2:C50). This will count the total number of unique values found across both specified areas.
Is there a limit to how many unique values Google Sheets can count?
While there is no specific limit for the COUNTUNIQUE function itself, you are limited by the overall cell limit of a Google Sheet (currently 10 million cells). Extremely large datasets may experience slower calculation times.
How do I count unique values based on a date range?
Use COUNTUNIQUEIFS. Set your criteria range to the date column and your criterion to a date or a cell reference containing a date. For example: =COUNTUNIQUEIFS(A2:A, B2:B, ">="&DATE(2023,1,1)).
What is the difference between UNIQUE and COUNTUNIQUE?
UNIQUE is a function that returns a list (an array) of all the distinct values it finds. COUNTUNIQUE is a function that returns a single number representing how many distinct values exist.