cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
deaconb Frequent Visitor
Frequent Visitor

Extract text from string without delimeter

I'm trying to extract a document number from a string of text in power query. The document number always starts with "S" and contains 6 total characters including the "S", ex. S00001. The problem I'm facing is that there are no consistent delimiters which I can use to break down the text string. 

 

I also don't want to get the numbers from the string, keep the first 5, then add the "S" prefix back on because I don't trust that as a future-proof solution. 

 

 

Here is an example of the varying data: 

sample listing.png

 

 

 

 

 

 

 

Any help is greatly appreciated!!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Re: Extract text from string without delimeter

@deaconb 

 

Try this custom column.

See attached file as well. it works with your sample data

 

=let mylist=List.Select(
    List.Transform(
    List.Transform({0..99999},each Text.From(_)),
    each "S" & (if Text.Length(_)<5 then Text.Repeat("0",5-Text.Length(_))&_ else _))
    ,
    each Text.Length(_)=6),
myname=[Name]
 in
 Text.Combine(
List.Select(mylist,each Text.Contains(myname,_) ),",")

extractee.png

Try my new Power BI game Cross the River

View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: Extract text from string without delimeter

Hi @deaconb 

Here is a useful article for reference:

Text Extraction using the M Language with Power BI

 

It may be easier to do with DAX , could you accept?

 

Best Regards

Maggie

deaconb Frequent Visitor
Frequent Visitor

Re: Extract text from string without delimeter

Thanks fr that link, Maggie. Unfortunately, that doesn't exactly get me the extraction methodology I'm looking for. I guess I basically am looking to define a data pattern, S##### and have it extracted from the string. 

Super User III
Super User III

Re: Extract text from string without delimeter

@deaconb 

 

Try this custom column.

See attached file as well. it works with your sample data

 

=let mylist=List.Select(
    List.Transform(
    List.Transform({0..99999},each Text.From(_)),
    each "S" & (if Text.Length(_)<5 then Text.Repeat("0",5-Text.Length(_))&_ else _))
    ,
    each Text.Length(_)=6),
myname=[Name]
 in
 Text.Combine(
List.Select(mylist,each Text.Contains(myname,_) ),",")

extractee.png

Try my new Power BI game Cross the River

View solution in original post

deaconb Frequent Visitor
Frequent Visitor

Re: Extract text from string without delimeter

That script worked perfectly - thank you so much! I can't tell you how much manual data cleansing you just prevented from having to do weekly!!

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors