excel - Count unique combination of the concatenation of two columns -


i have 2 columns, adjacent, , need unique count of resulting values concatenating 2 columns , need relate them value of column a. example:

cola colb    x    x b    y b    y b    z c    x c    y c    z 

count a: 1
count b: 2
count c: 3

i relate them via named lists, either 1 list containing both columns or 2 named lists of 1 column each. prefer not use array function, count function summation value. fine using vba , custom functions. columns not have blank values , have data, not believe need error checking.

edit
can count of distinct permutations in namedlist contains cola & colb. can't generate if statement tests if namedlist:cola == 'a'. have 3 distinct values cola , fine generating 3 different functions test a, b & c separately. below gives count of distinct permutations of namedlist show above, equals 6.

=sumproduct((namedlist<>"")/countif(namedlist,namedlist&"")) 

there fairly standard method of gaining unique count using sumproduct function , countif functions. can adapted unique-over-multiple-columns byt swapping out countif countifs function.

        unique count 2 columns

the formula in e4 is,

=sumproduct((a$2:a$99=$d4)/(countifs(a$2:a$99, a$2:a$99&"", b$2:b$99, b$2:b$99&"")+(a$2:a$99<>$d4))) 

to adapt above formula named range, use index function peel out columns 2 dimensional cell range.

=sumproduct((index(namedlist, 0, 1)=$d4)/(countifs(index(namedlist, 0, 1), index(namedlist, 0, 1)&"", index(namedlist, 0, 2), index(namedlist, 0, 2)&"")+(index(namedlist, 0, 1)<>$d4))) 

fill down necessary.

the biggest obstacle when designing 1 of these avoiding #div/0! error. appended empty strings , reversed criteria in denominator prevent.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -