Author: Oscar Cronquist Article last updated on September 10, 2019

This article demonstrates a formula that counts unique distinct values filtered from an Excel defined Table.

Debra Dalgleish described in an article how to create a Line Between Dates in Filtered List. She modified a formula by Laurent Longre found here: Excel Experts E-letter from John Walkenbach's web site.

I remember a post I did about extracting unique distinct values from a filtered table (udf and array formula that also was inspired by Laurent Longre's formula.

The Excel defined Table shown in the image above is named Table2. There are forenames in column A. The table is filtered with "Finland" and "Mexico" in column C, the following array formula counts unique distinct values based on a filter applied to an Excel defined Table.

What you will learn in this article

  • Build a formula that counts unique distinct values in a filtered table using a modified version of Laurent Longre's formula.
  • Identify filtered values using the SUBTOTAL and OFFSET function.
  • How to reference a column in an Excel defined Table, in a formula.
  • Convert boolean values to numerical equivalents
  • Convert text values to unique numbers based on the order as if they had been sorted from A to Z.
  • Count unique distinct numbers

Array formula in A26:

=SUM(--(FREQUENCY(IF(SUBTOTAL(3, OFFSET(Table2[First Name], MATCH(ROW(Table2[First Name]), ROW(Table2[First Name]))-1, 0, 1)), COUNTIF(Table2[First Name], "<"&Table2[First Name]), ""), COUNTIF(Table2[First Name], "<"&Table2[First Name]))>0))

How to create an array formula

  1. Copy above array formula
  2. Double click cell A26 to see the prompt.
  3. Paste array formula to cell.
  4. Press and hold Ctrl + Shift simultaneously.
  5. Press Enter once.
  6. Release all keys.

Explaining array formula in cell A26

Step 1 - Create an array of ranges

When you use an array of numbers in OFFSETs second argument an array of ranges is returned, this makes it possible to evaluate each value using the SUBTOTAL function.

The MATCH function creates an array of numbers in sequence from 1 to as many as there are values in column 'First Name' in Excel defined Table Table2.

MATCH(ROW(Table2[First Name]), ROW(Table2[First Name]))