TEXTSPLIT not working as expected inside of BYROW. Workaround?

felixstraube

Well-known Member
Joined
Nov 27, 2023
Messages
835
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hi all.
I was working on a LET formula that returned an array. Each element of the array contained text separated by semicolons. Then I wanted to work on each element with BYROW and separate the text of each element into an with TEXTSPLIT and work with the value of the last column. But, it wasn't working as expected. TEXTSPLIT apparently only returned the first element.

A simplified example would be the following:

As you can see, when I concatenate the input array with "" (which I suppose is something similar as the data I got in the formula I was working on), the formulas stops working as expected.
As if when the input is a range it works, but if it is an array (even a hard coded array, {"1;2";"3;4"}), it won't work.
Can you tell me why? Is there a workaround?

Thanks in advance!

Book9.xlsx
ABCD
1InputWorkingNot working
21;221
33;421
4
521
643
7
81|21
93|43
Sheet9
Cell Formulas
RangeFormula
C2:C3C2=LET( d, A2:A3, BYROW(d, LAMBDA(x, COLUMNS(TEXTSPLIT(x, ";")))) )
D2:D3D2=LET( d, A2:A3&"", BYROW(d, LAMBDA(x, COLUMNS(TEXTSPLIT(x, ";")))) )
C5:C6C5=LET( d, A2:A3, BYROW(d, LAMBDA(x, CHOOSECOLS(TEXTSPLIT(x, ";"),-1))) )
D5:D6D5=LET( d, A2:A3&"", BYROW(d, LAMBDA(x, CHOOSECOLS(TEXTSPLIT(x, ";"),-1))) )
C8:C9C8=LET( d, A2:A3, BYROW(d, LAMBDA(x, TEXTJOIN("|",,TEXTSPLIT(x, ";")))) )
D8:D9D8=LET( d, A2:A3&"", BYROW(d, LAMBDA(x, TEXTJOIN("|",,TEXTSPLIT(x, ";")))) )
Dynamic array formulas.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
As you are dealing with a single column, I would use MAP rather then BYROW.
As to why BYROW doesn't work, I've no idea.
 
Upvote 0
Workaround here would be this (provided it results in 2 columns to allow you work with the last one):

Excel Formula:
=DROP(REDUCE("",A2:A3,LAMBDA(a,b,VSTACK(a,TEXTSPLIT(b,";")))),1)
 
Upvote 0
This should take the last element even if the number of elements is not the same:

Excel Formula:
=MAP(A2:A3,LAMBDA(c,
LET(
a,TEXTSPLIT(c,";"),
b,COLUMNS(a),
CHOOSECOLS(a,b))))
 
Upvote 0
And BYROW option:

Excel Formula:
=BYROW(A2:A3,LAMBDA(a,CHOOSECOLS(TEXTSPLIT(a,";"),2)))
 
Upvote 0
try this
Excel Formula:
=BYROW(A2:A3&"",LAMBDA(a,CHOOSECOLS(TEXTSPLIT(a,";"),2)))

or this:

Excel Formula:
=BYROW({"1;2";"3;4"},LAMBDA(a,CHOOSECOLS(TEXTSPLIT(a,";"),2)))

That was the reason I posted the question. I don't get it why it doesn't work. But luckily we have other options.

This should take the last element even if the number of elements is not the same:
For the last element you can also use CHOOSECOLS(array, -1).
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Thanks RoryA. That's great.
Now why does BYROW transform each elemento of A3:A4&"" into an array but not each element of A3:A4?
Why does MAP not do that? Is there an explanation for that or should we simply accept that excel work like this?
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top