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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
sploits
New Member

Find Text (Number) in text string (Beginning with) and return it in Custom Column

Hi,

 

I have been searching high and low for an answer to this and so far can't find anything.

 

Within Power Query I have a column that I want it to find text (a number) that begins with the same 4 numbers and then return that as a single entry in a custom column. the Issue I have is that the number of delimiters change every now and again so I can't use the extract function. The source data can't be changed as it comes from client level and is locked in.

 

So as an example the text in the cell within Power Query looks like this.

 

ABC-Works-North Project-NP 2 - 5001123456 - Concrete Pour

ABC - Works - South-Project - SP1 - 5001256852 - Light Fitting

ABC - Works-West Project- 5001985500 - Room Painting

 

The part I want to extract is the numbers that begin with 5001 (so 5001123456, 5001256852 etc). These 4 starting numbers will never change (so hopefully make it easier to extract......).

The issue is that the delimiter (-) changes as it is sometimes in a title (South-Project for example) and sometimes it isn't the same place (sometimes 5 delimiters across, sometimes 4, sometimes 6, sometimes spaces and sometimes not (if that is relevant)).

 

I currently do this in excel using a MID and FIND function and it works well so was hoping Power Query could do something similar. Not the end of the world if not as I can dump the data into an Excel table and have that do the formula before uploading to SharePoint but would have preferred to get the source data file, add that to SharePoint and then have Power Query do the work which then would link nicely into my Power Bi report (the 5001 numbers are our unique reference to other reports so would bring it all together nicely).

 

Many thanks

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

=List.Select(Text.SplitAny([YourColumnName],Text.Remove([YourColumnName],{"0".."9"})),each Text.StartsWith(_,"5001") and Text.Length(_)=10){0}?

View solution in original post

10 REPLIES 10
sploits
New Member

@wdx223_Daniel That worked perfectly!!! Thank you so much!

wdx223_Daniel
Super User
Super User

=List.Select(Text.SplitAny([YourColumnName],Text.Remove([YourColumnName],{"0".."9"})),each Text.StartsWith(_,"5001") and Text.Length(_)=10){0}?

Hi Daniel, thanks for sharing this ! Could you please help me with the formula you created? Is it simlpy a new step inserted in the column or simply a custom column? 

Hi @OmarAl,

 

add that code as custom column and replace both [YourColumnName]


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Many thanks for the reply 🙂 

OxO compan Inc. - PO 4500806733/280

or

Xyz Limtd. - PO 4500806733_10

My column has such text in the above. I tried manipulating the characted in your formula from {10} to {13}, but unfortuantely it's not reading the numbers after the "/" or "_". Any recommendation?

OmarAl_0-1714472958101.png

 

 

What should be the output of 2 examples you've provided?


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Ideally, to read the "/280" or "_10" after the 10 digits. "45xxxxxxxx"

 

Or to read eaverything until it finds space " ". That's where I know the Purchase Order is complete 🙂

What about this?

Text.Range([YourColumnName], 13)

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi I found another workaround but would be great if you can giveme the whole forumla 🙂 Where should I plug the

Text.Range([YourColumnName], 13) 

Custom Column

 

dufoq3_1-1714635704668.png

 

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors