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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rajrajsha
Frequent Visitor

Split last characters before the number from column

Hi Team,

I'm trying to split a column that contains text and number into two seperate columns, one containing the number and other contains the character.

Below is the sample data how it looks.. I need to extract numbers and text seperately..

Please ignore if the text character is in the middle of the string. (Ex. 170M01788) 

sourceNumberText
170M01830X170M01830X
016 260423XXX016 260423XXX
170M01788170M01788 
170M02313X170M02313X
002P113748002P113748 
016 273150AM016 273150AM

 

Number and Text columns is what im expecting.

 

Thanks..

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@rajrajsha 

You can do it two steps:
Choose Digit to Non Digit

Fowmy_0-1653482006922.png

Then choose Merge Columns under Trasnform tab after selecting 1st and 2nd columns

Fowmy_1-1653482100105.png


Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ38DUwtDA2iFCK1YlWMjA0UzAyMzAxMo6IgIhAFJhbWCB4RsaGxlDlBkYBhobG5iYWCN3mxoamBo6+SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [source = _t]),
    #"Split Column by Character Transition" = Table.SplitColumn(Source, "source", 
Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"source.1", "source.2", "source.3"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition",{"source.1", "source.2"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Source")
in
    #"Merged Columns"

Result

Fowmy_2-1653482148164.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@rajrajsha 

You can do it two steps:
Choose Digit to Non Digit

Fowmy_0-1653482006922.png

Then choose Merge Columns under Trasnform tab after selecting 1st and 2nd columns

Fowmy_1-1653482100105.png


Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ38DUwtDA2iFCK1YlWMjA0UzAyMzAxMo6IgIhAFJhbWCB4RsaGxlDlBkYBhobG5iYWCN3mxoamBo6+SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [source = _t]),
    #"Split Column by Character Transition" = Table.SplitColumn(Source, "source", 
Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"source.1", "source.2", "source.3"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition",{"source.1", "source.2"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Source")
in
    #"Merged Columns"

Result

Fowmy_2-1653482148164.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ38DUwtDA2iFCK1YlWMjA0UzAyMzAxMo6IgIhAFJhbWCB4RsaGxlDlBkYBhobG5iYWCN3mxoamBo6+SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [source = _t]),
    #"Split Column by Character Transition" = Table.SplitColumn(Source, "source", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c))),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition",List.RemoveLastN(Table.ColumnNames(#"Split Column by Character Transition"),1),Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Number"),
    #"Renamed Columns" = Table.RenameColumns(#"Merged Columns",{{List.Last(Table.ColumnNames(#"Merged Columns")), "Text"}})
in
    #"Renamed Columns"

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors