Power Formulas for Unique Data
Created by David Hager, Bob Umlas and Laurent Longre
The problem - to create an array containing only the unique items from an expanding column list. In other words, if items are typed down column A, what is the formula that will return the unique items? The following example further illustrates the problem.

In this case, the array should be {”a”;”b”;1;3}. Then, if additional values
are added:

the array should be {”a”;”b”;1;3;”c”;”d”}. The answer to this problem has eluded me for years, but with recent input from Bob and Laurent, I have successfully constructed a solution to this problem. The formula is somewhat long, so it is necessary to define parts of the formula to simplify the final form.
Create a defined name with a Name of TheList and a Refers to of:
=OFFSET(Sheet1!$A$1,,,COUNTA(Sheet1!$A:$A),)
This formula creates the expanding range for the items as they are entered
into column A.
Define sArray as:
=SMALL(IF(MATCH(TheList,TheList,0)=ROW(TheList),ROW(TheList),""),
ROW(INDIRECT(”1:”&SUM(N(MATCH(TheList,TheList,0)=ROW(TheList))))))-1
This formula contains several important elements that require explanation. The formula
IF(MATCH(TheList,TheList,0)=ROW(TheList),ROW(TheList),"")
returns an array of positions for the unique items that is the same size as the TheList array, where the duplicates items are now represented by empty strings. The formula
ROW(INDIRECT("1:"&SUM(N(MATCH(TheList,TheList,0)=ROW(TheList)))))
returns an array of numbers from 1 to n, where n is the number of unique items in the list, as calculated by the formula
SUM(N(MATCH(TheList,TheList,0)=ROW(TheList))).
What is desired is an array that contains the unique positions with no empty strings. This is accomplished by the use of the SMALL function which, along with the LARGE function, is unique among Excel functions in its ability to create different sized arrays than the array used in the 1st argument if the 2nd argument is also an array. The -1 is used to adjust the item positions for use in the formula shown below.
Define TheUniqueArray as:
=IF(T(OFFSET(TheList,sArray,,1))="",N(OFFSET(TheList,sArray,,1)),T(OFFSET(TheList,sArray,,1)))
The formula
OFFSET(TheList,sArray,,1)
is an array of single element arrays, as explained in detail in the 1st issue of EEE. It can be converted into a normal array by using the N or T functions. Both N and T are used here since TheList can contain either text or numeric items.
WARNING: This formula can take a while to calculate if TheList is long. One thousand items took a couple of seconds on my Latitude D810.




