Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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
Solved! Go to Solution.
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
Proud to be a 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
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
Proud to be a Super User! | |
@JonPT See if this similar solution helps: Solved: Remove first characters that are numbers - Microsoft Fabric Community
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
70 | |
57 | |
37 | |
36 |
User | Count |
---|---|
85 | |
65 | |
60 | |
46 | |
45 |