I can't for the life of me figure out how to create a generalized formula to convert the following:
Name | cool | smart | funny | ... |
Bill | | x | x | |
Sally | x | x | | |
Bob | x | | x | |
Cindy | | | | |
Steve | x | | x | |
Carol | | | x | |
Bob | | x | | |
... | | | | |
Into something like this:
Bill:smart,funny
Sally:cool,smart
Bob:cool,funny
Cindy:
Steve:cool,funny
Carol:funny
Bob:smart
I'd like it to be able to work for an arbitrary number of columns and rows. Is there any way to achieve this without the need for "dragging?" Ie with ARRAYFORMULA
s.
Here is a link to an example Google Sheet.
Well, this is a bear of a hack, but it works. It will work for arbitrary rows and arbitrary columns, without any formula dragging.
=ARRAYFORMULA(REGEXREPLACE(REGEXREPLACE(TRANSPOSE(SPLIT(CONCATENATE({Data!A2:A&":", REGEXREPLACE(Data!B2:O, "x", REGEXREPLACE(Data!B1:O1, "$", ",")), IF(LEN(Data!A2:A)=LEN(Data!A2:A), "|")}), "|")), ",$", ""), "^:$", ""))
A few caveats:
I put the formula to work - you can view the spreadsheet by clicking here
The "Result" sheet has the formula and output that you wanted.
hope, this works:
=ArrayFormula(TRANSPOSE(SPLIT(ArrayFormula(CONCATENATE(A2:A8&": /")),"/"))&SUBSTITUTE(trim(transpose(query(transpose(IFERROR(ArrayFormula(HLOOKUP(REGEXREPLACE(B2:D8,"x","1")*1*COLUMN(B2:D8)*row(B2:D8)^0,{COLUMN(B2:D8);B1:D1},2,0)),"")),,counta(B1:D1))))," ",", "))
my sample in action =)
Update
I figured out how to make the formula shorter:
=ARRAYFORMULA(TRANSPOSE(SPLIT(ArrayFormula(CONCATENATE(A2:A8&": /")),"/"))&SUBSTITUTE(trim(transpose(query(transpose(REPT(B1:D1,B2:D8="x")),,counta(B1:D1))))," ",", "))
The formula above work's the same. It uses the trick, proposed here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.