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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Yqy
Helper I
Helper I

Extract consecutive 8 digit number from column contains text & number

the numbers seperated by the text or delimiter were merged to form the 8 digit number, and i don't want this to happen

DATA                                                what I have what I need

ABC- AB12345-12345678-AB1234567812345678
ABS-12345678-ABV1234567812345678
Abd=IUY=BGTYH-AI789_123456781234567812345678
T12345678-123451234567812345678
Abx-ABC23456789-123456781234567812345678
ABA1234HDSC876512348765 
BGS-123-4567812345678 
bsg-123-123456781234567812345678
BFH-12345678-1231234567812345678
1 REPLY 1
danextian
Super User
Super User

Hi @Yqy ,

 

Please  try the script below. What it does it converts the  text string into  a list, converts the items into a number if can be else null, then filters the list to exclude null, converts the list back into a text string, extracts the first  8 characters only then convert it back to  number.

danextian_0-1678350353382.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRy1lVwdDI0MjYx1QWTZuYWuo5OSrE6IMlgZLEwiGBSiq1naKStk3tIpIeuo6e5hWU8TBFYQQhcC5gB1VQBNMAZKmGpi6LB0ckRxPdwCXa2MDeDaHByB1uti1CVVJwOFkHR6uTmoYtsnVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DATA = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Convert to List", each Text.ToList([DATA])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Get Number", each List.Transform([Convert to List], each try Number.From(_) otherwise null)),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Filter List", each List.Select([Get Number], each _ <> null)),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom2", {"Filter List", each Text.Combine(List.Transform(_, Text.From)), type text}),
    #"Added Custom3" = Table.AddColumn(#"Extracted Values", "First8", each Number.From(Text.Start([Filter List],8)), Int64.Type)
in
    #"Added Custom3"

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.