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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.