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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
JonPT
Regular Visitor

Extract Alphanumeric Value from String

Hi Power BI Desktop Forum

I'm trying to extract an 8-character alphanumeric value from a column in Power BI desktop.

The pattern to extract is: first 2 characters are lower case a-z, followed by any 6 numbers and can be anywhere in the column.

The extracted 8 character alphanumeric should then be added to a new column

If the input column contains no 8-character (2 a-z and 6 numbers) alphanumeric then output null to the output column.

 

INPUT_COLUMN

ab123456

zy654321

fg456123

some-text-ab123456

some-zy654321-text

fg456123-some-text

some-text

some-other-text

 

OUTPUT_COLUMN

ab123456

zy654321

fg456123

ab123456

zy654321

fg456123

null

null

 

Tried all combinations of Text.Range, Text.PositionOf, Text.Select, Text.Middle, Text.Length, Text.Remove with no success

 

Really hoping you can help me here.

 

Thanks in advance

 

Regards

JonPT

1 ACCEPTED SOLUTION
Kaviraj11
Solution Sage
Solution Sage

Hi,

 

Create a custom column  as below

 

= let
Source = [String],
Pattern = List.First(List.Select(List.Transform({0..Text.Length(Source)-8}, each Text.Middle(Source, _, 8)), each Text.Length(_) = 8 and Text.Middle(_, 0, 2) = Text.Select(Text.Middle(_, 0, 2), {"a".."z"}) and Text.Middle(_, 2, 6) = Text.Select(Text.Middle(_, 2, 6), {"0".."9"})))
in
if Pattern = null then null else Pattern

 

Kaviraj11_0-1728062809030.png

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

4 REPLIES 4
Kedar_Pande
Super User
Super User

In the Power Query Editor, click on "Add Column" and then select "Custom Column."

if Text.ContainsAny([INPUT_COLUMN], {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}) 
then
try
Text.Select(Text.Middle([INPUT_COLUMN], Text.PositionOfAny([INPUT_COLUMN], {"a".."z"}, Occurrence.First), 2), {"0".."9", "a".."z"})
otherwise
null
else
null

If this helped, a Kudos 👍 or Solution mark would be great!
Cheers,
Kedar Pande
www.linkedin.com/in/kedar-pande

Kaviraj11
Solution Sage
Solution Sage

Hi,

 

Create a custom column  as below

 

= let
Source = [String],
Pattern = List.First(List.Select(List.Transform({0..Text.Length(Source)-8}, each Text.Middle(Source, _, 8)), each Text.Length(_) = 8 and Text.Middle(_, 0, 2) = Text.Select(Text.Middle(_, 0, 2), {"a".."z"}) and Text.Middle(_, 2, 6) = Text.Select(Text.Middle(_, 2, 6), {"0".."9"})))
in
if Pattern = null then null else Pattern

 

Kaviraj11_0-1728062809030.png

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Many thanks Kaviraj11 Your solution worked perfectly

Greg_Deckler
Community Champion
Community Champion

@JonPT See if this similar solution helps: Solved: Remove first characters that are numbers - Microsoft Fabric Community



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.