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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
vippankapoor
Employee
Employee

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
Super User
Super User

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


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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.


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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

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 

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.  

 

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.