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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
314mp_M0th4
Resolver I
Resolver I

Looking for a unspecific series of numbers in strings from different columns for a calculated column

Hello. I have a Dataset with two string columns. Only one column has a string for each row. In this string is some text and somewhere in this text is a 7 digit number, either split with a widespace or not split at all. How can I parse the string to find the digits?

1 ACCEPTED SOLUTION

Quick thought - this will leave you with errors if the field doesn't contain a 7 digit number. Use try and otherwise to leave the field blank if not found:

 

try List.Select(List.Transform(Text.Split([Column1], " "), each Text.Select(_, {"0".."9"})), each Text.Length(_) = 7){0}

otherwise ""

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

View solution in original post

5 REPLIES 5
Ahmedx
Super User
Super User

pls try this

Screenshot_3.png

DOLEARY85
Super User
Super User

Hi,

 

You could try something like this in a custom column in Power Query, just change Column1 to your Column Name:

 

List.Select(List.Transform(Text.Split([Column1], " "), each Text.Select(_, {"0".."9"})), each Text.Length(_) = 7){0}

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Quick thought - this will leave you with errors if the field doesn't contain a 7 digit number. Use try and otherwise to leave the field blank if not found:

 

try List.Select(List.Transform(Text.Split([Column1], " "), each Text.Select(_, {"0".."9"})), each Text.Length(_) = 7){0}

otherwise ""

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Thanks, now there was actually a condition I didn't think of, what if the series of digits can only be 7 digits long and there are bits that are longer than 7 and the code shouldn't catch?

The current formula will only catch the 7 digits if you wanted to modify to capture all digits on the first occurance of digits you could change the = 7 to >0:

 

try List.Select(List.Transform(Text.Split([Column1], " "), each Text.Select(_, {"0".."9"})), each Text.Length(_) >0){0}

otherwise ""

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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