1
votes

I'm having a hard time wrapping my mind around how to approach this...

Say I have a table with several items with different potential properties, which are assigned a boolean value for each property for each item. (in this case we have several options for each "color" and "size")

            |           Color                  |       Size     
-----------------------------------------------------------------------
    Item    | Red | Blue | White | Black | Tan | Large | Medium | Small
-----------------------------------------------------------------------
    Pants   |     | y    |       | y     | y   | y     | y      | y    |
    Shirt   | y   |      | y     | y     |     | y     | y      | y    |
    Skirt   |     | y    | y     |       |     |       | y      | y    |
    Socks   | y   | y    | y     | y     | y   | y     | y      | y    |

And I want to then output this into a single column like:

Pants, Blue, Large
Pants, Blue, Medium
Pants, Blue, Small
Pants, Black, Large
Pants, Black, Medium
Pants, Black, Small
Pants, Tan, Large
Pants, Tan, Medium
Pants, Tan, Small
Shirt, Red, Large
etc etc

So, I'm trying to populate a column with all the possible results of the true values for each row, concatenated with the header for each column that has a true value. In this example, it would further break out color and size for each item.

Thoughts on the best approach to this in Google Sheets?

Example sheet: https://docs.google.com/spreadsheets/d/199msbUtUuZzb0HvBMgjQW98hRt3StFEyUFfTfLzSQzw/edit?usp=sharing

2
Thanks for sharing this previous answer also. I was able to get this to work, but needed to add one more step to concatenate the columns into one. Your custom answer below solved that too.Matt G
There's a hidden formula I recently discovered called =FLATTEN(). It makes these kinds of problems much simpler. Happy to demo on your sample sheet. Can you make it editable?MattKing
Sure, sounds great thanks MattKing!Matt G
So, i hadn't realized there were actually TWO datatables that needed retabulation (color and size). so Flatten() won't work. I do have another method that might be a little easier to work with, and I'll post it up.MattKing

2 Answers

1
votes

on a small scale:

=ARRAYFORMULA(TRANSPOSE(SPLIT(TEXTJOIN("\", 1, 
 IF(B3:F6="y", REPT(A3:A6&", "&B2:F2&"\", MMULT(N(G3:I6="y"), 
 TRANSPOSE(COLUMN(G2:I2)^0))), )), "\"))&", "& 
 TRANSPOSE(SPLIT(JOIN(" ", REPT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
 IF(G3:I6="y", G2:I2, )),, COLUMNS(IF(G3:I6="y", G2:I2, )))))&" ", 
 MMULT(N(B3:F6="y"), TRANSPOSE(COLUMN(B3:F6)^0)))), " ")))

0


for just combo of two:

=ARRAYFORMULA(QUERY(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(
 IF(B3:F="y", "♦"&A3:A&", "&B2:F2&"♦", ),,99^99)),,99^99), "♦")), 
 "where not Col1 starts with ' ' order by Col1"))

enter image description here


modded @MK formula to mimic CSV:

=ARRAYFORMULA(TRANSPOSE(QUERY(TRANSPOSE(QUERY(VLOOKUP(SEQUENCE(4*5*3, 1, 0)/(5*3)+3, 
 {ROW(A:A), A:A&",", IF(B:I="y", {B2:F2&",", G2:I2}, )},
 INT(MOD(SEQUENCE(4*5*3, 1, 0), {9^99, 5*3, 3})/{9^99, 4, 1})+{2, 3, 3+4}),
 "where Col2<>'' and Col3<>''")),,9^99)))
1
votes

For problems like these, I like to use a VLOOKUP() with an [index] value that is made up of an array constructed out of some of the parameters of your data. I made a new tab called mK.Help and put this formula there which will retabulate your data into the way you're hoping (i think).

If you definitely want comma separated, I can help with that, but usually folks just want the data in columns. each of the parameters is fed by a simple formula counting the various aspects of your data. The big reorganizing formula can be rewritten to include each of those formulae instead of referring to a helper cell, but I have found that it is easier for folks to understand what's going on when I leave it broken out like that.

=ARRAYFORMULA(QUERY(VLOOKUP(SEQUENCE(Q3*Q4*Q5,1,0)/(Q4*Q5)+Q2,{ROW(A:A),A:A,IF(B:I="y",B2:I2,)},INT(MOD(SEQUENCE(Q3*Q4*Q5,1,0),{9^99,Q4*Q5,Q5})/{9^99,Q5,1})+{2,3,3+Q4}),"where Col2<>'' and Col3<>''"))