Many languages have functions to process lists (array). These functions usually return a list, so you can pass that to another list function. This chaining of functions is really powerful.
UNIX provides this sort of chaining capability. If I had a cities (with some repetitions) and I wanted to find out how many started with the letter 'A', I'd just type:
cat cities | sort | uniq | grep "^A" | wc
cat: types the cities.
sort: sorts the cities alphabetically.
uniq: finds unique cities (works only if sorted - that's why we had to sort the list).
grep: filters the cities. Only allows cities beginning with A.
wc: word count
To do this on Excel, the only way is to
But ideally, I'd like a 1-line formula like
=LENGTH(UNIQUE(GREP("^A", range)))
Excel doesn't provide these functions by default, but you can add them as user defined functions. Doing this lets you condense several cells into one. Instead of having to copy all your data into a set of unique values, and then adding a column for the first cell, the entire operation can be condensed into one formula.
I consider the following functions the a basic set for list processing.
I created these UDFs. You can download the functions and play with them. Below are some tasks that you can do with them, that are difficult otherwise.
=INDEX(REVERSE(STRSPLIT("\", filename)), 1)=LENGTH(UNIQUE(range))
=LENGTH(INTERSECTION(range1, range2))
=LENGTH(STRSPLIT(" ", string))=SMALL(UNIQUE(range), 5)
=COUNT(Range1)+COUNT(Range2) - COUNT(INTERSECTION(Range1,Range2))
=STRJOIN(",",UNION(DIFFERENCE(Range1,Range2),
DIFFERENCE(Range2,Range1)))=LENGTH(Range)-LENGTH(UNIQUE(Range))
=MVLOOKUP(A1,Lookup_Range,Return_Range)
=COUNT(UNIQUE(MVLOOKUP(A1,Lookup_Range,Return_Range)
This is a small sample. The power of list processing is phenomenal, especially when combined with array formulas. Download these macros and play with them!