Count unique distinct values in a large dataset with a date criterion
i have ~100K rows, and Excel is literally stalled when running the formula.
for the time being, i'm using a Pivottable and using a COUNTA function to count unique distinct value. Not automated but it's near-instantaneous to get the number ![]()
have tried lazyvba's code. works fine, but it is not efficient (crawling for list more than >100K rows).
my pivottable is simple: dates and products. no other columns, formulas, etc.
Answer:
This blog post demonstrates how to count unique distinct filtered values in a large data set using excel 2007 table and simple formulas. Read this post if you have a smaller data set: Count unique distinct values in a column in excel
Table of contents
- Create a table
- Sort the table
- Two simple formulas
- Count unique distinct filtered values
- Apply date filters
Create an excel table
- Select data range
- Click "Insert" tab on the ribbon
- Click "Table" button
- Click OK.
Sort Products
- Click black arrow near header "Products"
- Click "Sort A to Z"
Create a new formula in cell C2
- Select cell C2
- Type formula in cell:=IF(SUBTOTAL(103, B2)=0, C1, B2)
- Press Enter
Create a new formula in cell D2
- Select cell D2
- Type formula in cell:=(C2<>C1)*1
- Press Enter
- Select a cell below the table
- Type in cell:=SUM(D2:D18)
- Press Enter
Filter dates
- Click black arrow on table header "Dates"
- Filter dates
The formulas used in this example are simple and fast. This technique should work on a really large data set.
Download excel 2007 file *.xlsx
Related posts:
Excel udf: Count unique distinct values in a large dataset
Excel udf: Remove duplicates from a large dataset
Count unique distinct values using date criteria in a range in excel
Count unique distinct values in two columns with date criteria in excel
Filter unique distinct and duplicate values from a large data set in excel 2007





















