2

I have a column of strings, example below. Each string is a delimited combinations of texts. Each row has different number of texts. I want to create a single column with one text per row based on this column.

FROM:

a;b
x;y;z
p;q;r;s;t

TO:

a
b
x
y
z
p
q
r
s
t

How do I achieve this using a single formula?

I tried TRANSPOSE(TEXTSPLIT(TEXTJOIN(";",TRUE, data),";")) However, this fails because the TEXTJOIN part results in more than 32767 characters.

I also tried building a 2D array of mxn where m=no. of rows in the original data and n=no. of texts. However, the MAKEARRAY still results in a single column. Had it worked, I would have used TOCOL or something similar to convert to a single column.

=MAKEARRAY(ROWS(data),COLUMNS(MAX(num_of_texts_in_each_row)), LAMBDA(r,c, LET(
drow, INDEX(data,r,1),
splits, TEXTSPLIT(drow,";"),
INDEX(splits,,c)
)))
2
  • 1
    Why is COLUMNS in there?
    – Rory
    Commented Nov 17, 2022 at 16:08
  • thank you!! that was an error and it solved the entire problem when i removed it.
    – dsauce
    Commented Nov 17, 2022 at 16:25

2 Answers 2

6

Another approach would be by using REDUCE:

=DROP(REDUCE(0,A1:A3,LAMBDA(a,b,VSTACK(a,TEXTSPLIT(b,,";")))),1)

enter image description here

REDUCE behaves like a BYROW, where the VSTACK stacks the spilled result per row on top of eachother after the full spill value. As it starts at 0, we use DROP the first value to get the desired result.

We could also avoid DROP, but that makes the formula more complicated and longer, but for reference: =REDUCE(TEXTSPLIT(A1,,";"),A2:A3,LAMBDA(a,b,VSTACK(a,TEXTSPLIT(b,,";"))))

6
  • Fantastic. Thanks! I was hoping that REDUCE would do it but my Excel version just received REDUCE a few days ago, haven't experienced it enough.
    – dsauce
    Commented Nov 17, 2022 at 19:38
  • It's very useful. See what happens if you change VSTACK to HSTACK and wrap it in IFERROR: =IFERROR(DROP(REDUCE(A1,A1:A3,LAMBDA(a,b,VSTACK(a,TEXTSPLIT(b,";")))),1),"")
    – P.b
    Commented Nov 17, 2022 at 19:44
  • 1
    Great stuff. I'm starting to think that REDUCE is fast-becoming the new function of choice: it can mimic, for example, BYROW, as you have shown here, and, more importantly, its in-built pseudo-recursive nature can also give it a distinctive edge over the other new functions in many situations. Commented Nov 17, 2022 at 19:46
  • 1
    Having said that, I have to say that I'm a little disappointed in MS for the fact that functions such as TEXTSPLIT are not able to generate an array of returns. Commented Nov 17, 2022 at 19:50
  • 1
    I thought the same, but I reckon that's because TEXTSPLIT has two conditions for splitting: by row and/or by column. That way a 2D array would be generated by the formula itself. That's probably why. I would've expected it to work in combination with BYROW if you where to spill the textsplit result horizontally by row, but in that case REDUCE seems to outsmart BYROW
    – P.b
    Commented Nov 17, 2022 at 20:01
2

Use:

=LET(
    rng,A1:A3,
    clm,MAX(BYROW(rng,LAMBDA(a,COUNTA(TEXTSPLIT(a,";"))))),
    TOCOL(MAKEARRAY(ROWS(rng),clm,LAMBDA(a,b,INDEX(TEXTSPLIT(INDEX(A1:A3,a),";"),b))),3))

enter image description here

1
  • thanks, this is exactly what i tried but made a minor mistake.
    – dsauce
    Commented Nov 17, 2022 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.