Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
I have a table and one column contains free text. I'm looking to add a column which will search the free text and extract anything which has a letter followed by 5 numbers.
For example - the below would be extracted:
D98765
d12345
D 54821
d 65411
This could be anywhere within the string of text. Is this possible?
Solved! Go to Solution.
@mwild ***Made a tweak to the code***
The following works. I will let you tweak the code further if you need to so I am not doing all your homework 😂
StringMatch =
VAR NoBlankFreeText =
SUBSTITUTE ( 'Sample Data'[FreeText], " ", "", 1 )
VAR UpperD =
FIND ( "D", NoBlankFreeText, 1, BLANK () )
VAR LowerD =
FIND ( "d", NoBlankFreeText, 1, BLANK () )
VAR PositionD =
IF ( ISNUMBER ( UpperD ), UpperD, LowerD)
VAR CheckNumbers =
ISERROR (
ISNUMBER ( VALUE ( MID ( NoBlankFreeText, PositionD + 1, 5 ) ) )
)
RETURN
IF (
NOT ( CheckNumbers ),
MID ( NoBlankFreeText, PositionD, 6),
"No Match"
)
With combination of LEFT or RIGHT function
Or you can use CONTAINSSTRING function e.g
MyCalculatedColumn = If(CONTAINSSTRING([TARGETCOLUMN];"searchforthis");TRUE();FALSE())
I am not sure how this will work when the end goal is "any letter followed by any numbers" when the letter and the numbers could be anything, e.g. it can be "Z 98765" or "b34561" or worse "!@#@!D48202@#!@".
The letter will always be "D" or "d"
There may be a space (or may not be) and then 5 numbers between 0 and 9
@mwild ***Made a tweak to the code***
The following works. I will let you tweak the code further if you need to so I am not doing all your homework 😂
StringMatch =
VAR NoBlankFreeText =
SUBSTITUTE ( 'Sample Data'[FreeText], " ", "", 1 )
VAR UpperD =
FIND ( "D", NoBlankFreeText, 1, BLANK () )
VAR LowerD =
FIND ( "d", NoBlankFreeText, 1, BLANK () )
VAR PositionD =
IF ( ISNUMBER ( UpperD ), UpperD, LowerD)
VAR CheckNumbers =
ISERROR (
ISNUMBER ( VALUE ( MID ( NoBlankFreeText, PositionD + 1, 5 ) ) )
)
RETURN
IF (
NOT ( CheckNumbers ),
MID ( NoBlankFreeText, PositionD, 6),
"No Match"
)
You can use CONTAIN function
You can do this using regular expression (using R or Python) in the query editor, Curbal here explains it really well
https://www.youtube.com/watch?v=9E3VsvFAge4
Regards,
Moiz
If this post helps, please "Accept" it as Solution to help other members find it.
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 45 | |
| 38 | |
| 34 | |
| 21 | |
| 17 |
| User | Count |
|---|---|
| 66 | |
| 65 | |
| 31 | |
| 26 | |
| 26 |