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

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

Reply
Anonymous
Not applicable

Extracting specific number form alphanumeric text

 

Hi. Need help in extracting consecutive numeric string from cell. for example extracting "987654321" from string below

 

"P06 Payroll 92 team 32A ACCRUAL 987654321 Sub"

 

Numeric string to be pulled can begin from any number however total digits in string will always be same. 

 

1 ACCEPTED SOLUTION

Not particularly elegant, but works for me:

 

(TextInput as text) =>
let
    Source = TextInput,
    Custom1 = Text.Split(Source, " "),
    Custom2 = List.Select(Custom1, each Text.Length(_) = 9),
    Custom3 = List.Transform(Custom2, each Text.ToList(_)),
    Custom5 = List.Select(Custom3, each List.MatchesAll(_, (li)=> List.Contains({"0".."9"}, li))){0},
    Custom4 = Text.Combine(Custom5)
in
    Custom4

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

8 REPLIES 8
Greg_Deckler
Community Champion
Community Champion

Does it always follow a specific term or number of spaces from the beginning or the end?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

there is  no specific place in string this might come. Dpending on user input (geogrpahically dispersed users), numeric string can  appear anywhere in the cell. Numeric string to be pulled out will always be 9 characters if that helps. 

There's no easy DAX way that I can think of off the top of my head, perhaps @ImkeF has an M way.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hello Greg, 

Thanks a lot for your help. 

 

regards

Not particularly elegant, but works for me:

 

(TextInput as text) =>
let
    Source = TextInput,
    Custom1 = Text.Split(Source, " "),
    Custom2 = List.Select(Custom1, each Text.Length(_) = 9),
    Custom3 = List.Transform(Custom2, each Text.ToList(_)),
    Custom5 = List.Select(Custom3, each List.MatchesAll(_, (li)=> List.Contains({"0".."9"}, li))){0},
    Custom4 = Text.Combine(Custom5)
in
    Custom4

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Following up with another solution i learned for this problem from my peer.

Replacing 9 with |9 (delimiter), extracting text after delimiter and replacing delimiter (|) with nothing. 

 

Regards, 

Vippan 

Anonymous
Not applicable

Thanks for the inputs. I am not trained with M query. Can  this be used while adding custom column? 

Will request you to share any quick tutorial that might help me to implement the solution.  

 

ImkeF
Community Champion
Community Champion

You can find that tutorial here: https://www.thebiccountant.com/2019/01/30/add-a-column-with-custom-function-code-in-power-query/ 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors