Unique Values with Criteria: How to Count Distinct
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator counts the number of unique values in a list that meet a specific condition. You enter your list of values, set a criterion (such as greater than 10 or equal to “yes”), and the calculator returns the count of distinct items that satisfy that condition. The result helps you analyze datasets where duplicates exist but you only want to count each qualifying item once.
Formula
The calculator uses a two-step process: first it filters the list to keep only values that meet the criterion (e.g., value > threshold), then it counts how many distinct values remain. In mathematical terms, if your list is L and your condition is C, the result is |{x ∈ L : C(x)}|, where the outer bars mean “number of elements in the set” and the set notation automatically removes duplicates.
For the example above, the condition is x > num. The formula filters L to values greater than num, then counts unique values. No explicit variable definitions are needed beyond the list and the threshold.
Worked Example
Using the default values: list = [5, 10, 10, 15, 20, 20], threshold = 10.
- Apply the condition x > 10: keep 15, 20, 20. (5 and 10 are not greater than 10.)
- Remove duplicates from the kept values: 15 and 20 (the second 20 is dropped).
- Count the remaining values: 2.
The calculator returns 2, matching the manual calculation.
When to Use This Calculation
Counting unique values with criteria is common in data analysis, inventory management, and survey processing. For example, you might have a list of customer IDs with repeated purchases, and you want to know how many distinct customers spent over $100. Or you have a log of website visits with user IDs and you need the number of unique visitors from a specific country. The calculation is also useful in quality control: given a list of defect codes, how many distinct defect types occurred more than five times? In each case, you need to filter first, then deduplicate.
How to Read the Result
The result is a whole number representing the count of distinct items that satisfy your condition. A result of 0 means no unique values met the criterion. A result equal to the total number of unique values in the list means all distinct items passed the filter. If your list has no duplicates, the count equals the number of items that meet the condition. If duplicates exist, the count will be less than or equal to the number of qualifying entries.
Common Mistakes
- Forgetting to deduplicate: Some users count all qualifying entries, not unique ones. For example, in the default list, 20 appears twice and both are above 10, but the unique count is 2, not 3.
- Mixing up > and ≥: If your threshold is 10 and you want to include 10, you need to use ≥, not >. The calculator uses > by default, so adjust the threshold accordingly.
- Using text criteria incorrectly: If your list contains text, the threshold comparison may not work as expected. This calculator is designed for numeric values.
- Ignoring case sensitivity: If you were to adapt this to text, “Apple” and “apple” would be considered different unique values in most programming languages. This calculator treats numbers only.
Limitations of the Formula
This calculation assumes your list is finite and that you can define a clear numerical condition. It does not handle empty lists gracefully (returns 0), and it treats all values as numbers. If your data includes blanks or non-numeric entries, they are ignored or cause errors depending on implementation. The formula also assumes the condition is a simple threshold; more complex criteria (e.g., between two numbers, or matching a pattern) would require a different approach. For large datasets, manual counting is error-prone; using a spreadsheet or programming language is recommended.
Frequently Asked Questions
How is this different from just counting unique values?
Counting unique values without a criterion would count every distinct item in the list. Here, you first filter the list to only those items that meet your condition (like greater than a threshold), then count distinct items among those. For example, in the list [1,2,2,3,4], unique values total 4, but unique values greater than 2 are only 2 (3 and 4).
What if my list has text values?
This calculator is designed for numeric values only. For text, you would need a different tool that supports string comparison. In general, you would filter by exact match or contains, then deduplicate. Many spreadsheet programs have functions like COUNTIFS combined with SUMPRODUCT to handle text.
Can I count unique values that meet multiple criteria?
Yes, but this calculator only supports a single threshold. For multiple criteria, you would need to combine conditions, such as values between 10 and 20, or values that are both above 10 and below 20. That would require a more complex formula, often using arrays or additional columns in a spreadsheet.
Why does the result not match my manual count?
Check whether you are accidentally counting duplicates. For example, if your list is [5,10,10,15] and you count values above 10, you might count 15 only once, giving 1. If you counted both 10s, you’d get 2, but 10 is not above 10. Also verify the threshold: is it > or ≥? The calculator uses strict greater-than.
What is the best way to do this in Excel or Google Sheets?
In Excel, you can use an array formula like =SUM(IF(FREQUENCY(IF(A1:A10>10, A1:A10), A1:A10)>0,1)) entered with Ctrl+Shift+Enter. In Google Sheets, you can use =COUNTUNIQUEIFS(A1:A10, A1:A10, “>10”). These are standard functions that accomplish the same result.
Does this calculator work for negative numbers?
Yes, negative numbers are treated normally. If your threshold is -5, then -3, 0, and 10 would all be included. Just ensure the threshold is set appropriately.
Related
Formula used
in list | Values | - | 5, 10, 10, 15, 20, 20 | 0 in num | Threshold | - | 10 | 0 out count | Unique values above threshold | - | count_unique_above(list, num) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.