Transpose Unique Values from Multiple Columns

2019-08-07 06:02发布

问题:

I'm trying to generate unique values in D1:F but my formula is not working. For example, row 1 has

A       B       C
milk    milk    44

the output should be:

D      E
milk   44

here is my formula and my sheet

=ARRAYFORMULA(unique(A1:C))

回答1:

UNIQUE works only in one dimension (row or column)

=QUERY(UNIQUE({A:A;B:B;C:C}), "where Col1 is not null", 0)


=ARRAYFORMULA(SPLIT(REGEXREPLACE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE({QUERY(QUERY(
 UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
 IF(LEN(A2:A), "♠"&A2:A&"♦"&B2:D, )),,999^99)),,999^99)), "♠")), "♦")),
 "select Col1, count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),
 "select Col1 offset 1",0),
 IF(QUERY(QUERY(UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
 IF(LEN(A2:A), "♠"&A2:A&"♦"&B2:D, )),,999^99)),,999^99)), "♠")), "♦")),
 "select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0), "offset 1",0)<>"", 
 QUERY(QUERY(UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
 IF(LEN(A2:A), "♠"&A2:A&"♦♀"&B2:D&",", )),,999^99)),,999^99)), "♠")), "♦")),
 "select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0), "limit 0",1),)})
 ,,999^99))), ", ♀", ", "), ",$", ), "♀"))