Forum Discussion
RL1
9 years agoFrequent Visitor
Split column based on text and numerical characters
Hi, I'm trying to split a column that contains text and number components into two seperate columns, one containing the text characters and another containing the numbers. i.e. I want to go ...
- 9 years ago
Instead I would propose Text.PositionOfAny as illustrated in this video.
Relevant parts of the code generated during video recording ("PreviousStep" is the name of your previous step):
#"Added Custom" = Table.AddColumn(PreviousStep, "Custom", each Text.PositionOfAny([Column1],{"0".."9"})), #"Inserted First Characters" = Table.AddColumn(#"Added Custom", "First Characters", each Text.Start([Column1], [Custom]), type text), #"Inserted Text Range" = Table.AddColumn(#"Inserted First Characters", "Text Range", each Text.Middle([Column1], [Custom]), type text), #"Removed Columns" = Table.RemoveColumns(#"Inserted Text Range",{"Column1", "Custom"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Text Range", "Number"}}), #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Number", Int64.Type}})
Greg_Deckler
9 years agoCommunity Champion
You could potentially use PostionOfAny function:
List.PositionOfAny("ABCBA", {"A","B"}, Occurrence.All) equals {0,1,3,4} You would probably have to use an M custom function or another function to return the lowest value in the list and then feed that to a Split.
MarcelBeug
9 years agoCommunity Champion
Instead I would propose Text.PositionOfAny as illustrated in this video.
Relevant parts of the code generated during video recording ("PreviousStep" is the name of your previous step):
#"Added Custom" = Table.AddColumn(PreviousStep, "Custom", each Text.PositionOfAny([Column1],{"0".."9"})),
#"Inserted First Characters" = Table.AddColumn(#"Added Custom", "First Characters", each Text.Start([Column1], [Custom]), type text),
#"Inserted Text Range" = Table.AddColumn(#"Inserted First Characters", "Text Range", each Text.Middle([Column1], [Custom]), type text),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Text Range",{"Column1", "Custom"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Text Range", "Number"}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Number", Int64.Type}})