Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
k2s2
Frequent Visitor

Split *multiple* columns by non-digit to digit

Hello,

 

Using the menus, I can split a column into two, which creates M code something like below if my column is named Column1

 

 

#"Split Column by Character Transition" = Table.SplitColumn(#"Capitalized Each Word", "Column1", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Column1.1", "Column1.2"})

 


But how can I do this for multiple columns at once?

 

It seems if I select all the columns that I want to transform, the Split Columns button is greyed-out

 

(Cross posted here: https://www.mrexcel.com/board/threads/split-multiple-columns-by-non-digit-to-digit.1202256)

6 REPLIES 6
k2s2
Frequent Visitor

Thanks for your reply Rocco,

When I applied the technqiue to my data it was adding another column and renaming both .1 and 2. but the data wasn't splitting between them.  The 2nd of each column was simply null.    

It tried to modify using the split by position (last character from teh right), which works manually, but when I tried this:

ColAreSplit= List.Accumulate(#"colstosplit", #"Capitalized Each Word", (s,c)=>Table.SplitColumn(s, c, Splitter.SplitTextByPositions({0, 1}, true),
{c&".1", c&".2"}))

 The columns split but I only see the headers

Anonymous
Not applicable

sei sicuro che sia il codice che ti ho dato io?

a me non sembra.

Like I said, the code you posted did not work with my data - it split the columns but null in the second column.  Then I tried a different split method described above, but since I don't know M, probably I made some mistake that does not display the rows 

Anonymous
Not applicable

multi columns split.JPG

 

as you can see this code produce the result you where looking for, seems to me.

 

 

Here colstosplit = {"Colonna1","Colonna2"} change this according to your needs

#Modificato Tipo# is the result  of the previuos step: for me is the source table on which to apply a succession of column splits

 

 

PS

 

If you show us the error you get or the situation you are just before start splitting, may be someone can find the rigth soltuion

 

I think I understand that, but your #"Modificato tipo" just changes the type of the selected columns to text, right?  Isn't it the next step colstosplit={"Colonna1","Colonna2"}, that defines the columns to apply the split to?

Also, what do the "s" and "c" refer to?  and the " (s,c)=>"

 

I'm trying to use your aprpoach but now with the Splitter.SplitTextByPositions (because I realised some records in the fields don't have a last character that is a digit). 

 

I can't find anything like that s & c in the function references for splitter functions (https://docs.microsoft.com/en-us/powerquery-m/splitter-functions)

 

Anonymous
Not applicable

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JcvBDcAgDEPRXXLmVhzSO3KRMwJi/zVKqeTb85/ToiEgaoi0Yo6oXd1WmebhEU7+gv0kn+SxiusSUzpNgwbzAJozubehOfz+smFrvQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Colonna1 = _t, Colonna2 = _t]),
    #"Modificato tipo" = Table.TransformColumnTypes(Origine,{{"Colonna1", type text}, {"Colonna2", type text}}),
    colstosplit={"Colonna1","Colonna2"},
    ts= List.Accumulate(colstosplit, #"Modificato tipo", (s,c)=>Table.SplitColumn(s, c, Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), 
     {c&".1", c&".2"}))

in
    ts

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.