cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Syndicate_Admin
Administrator
Administrator

Checking string of certain format

Hey Everyone, I am new to power query and this has had my head scratching is there anyway I can solve this?

 

Is it possible to check a string dynamically where AA****...BB where AA  and BB are alphabets while ****... represents any amount of integers. If that is possible i would like to return it to an new column

 

eg:                                Output

AB123456BC 3033       AB123456

AB1234BC 2022           AB1234

1 ACCEPTED SOLUTION

Use this

= Splitter.SplitTextByCharacterTransition({"0".."9"},{"A".."Z", "a".."z"})(Text.SplitAny([Input],"/-"" """){0}){0}

View solution in original post

4 REPLIES 4
AlB
Super User
Super User

Hi there

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnQyNDI2MTVzclYwNjA2VorVgYkBRYwMjIyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Column1", "Column1 - Copy"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Duplicated Column", "Column1 - Copy", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"Column1 - Copy.1", "Column1 - Copy.2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Character Transition",{"Column1 - Copy.2"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Column1 - Copy.1", "Output"}})
in
    #"Renamed Columns"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Vijay_A_Verma
Community Champion
Community Champion

Use this in a custom column where Input is column name

= Splitter.SplitTextByCharacterTransition({"0".."9"},{"A".."Z", "a".."z"})(Text.Split([Input]," "){0}){0}

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("i45WcnQyNDI2MTVzclYwNjA2VorVgYkBRYwMjIwgIoZOzi5uSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Input = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Splitter.SplitTextByCharacterTransition({"0".."9"},{"A".."Z", "a".."z"})(Text.Split([Input]," "){0}){0})
in
    #"Added Custom"

Hey Thanks, this works but there is a small issue.

Sometimes the records are as such 

AB1234/01BC

AB1234-01BC

 

how do i extract the above for that type of records

 

Use this

= Splitter.SplitTextByCharacterTransition({"0".."9"},{"A".."Z", "a".."z"})(Text.SplitAny([Input],"/-"" """){0}){0}

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.