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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jacquelineq
Helper I
Helper I

Extract substring from another column in Power Query

Hi, I have a column containing pdf filenames and I want to be able to extract text containing 'BODNNNNNNN' where N represents any single number. Is it possible to create a new custom column in Power Query?

 

BOD PDF filename Expected Output
File1.pdf  
File_BOD1234567_1.pdf BOD1234567
BOD7654321_final_1.pdf BOD7654321
BOD5555555(22Jan).pdf BOD5555555

 

Appreciate any advice! Thanks!

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

In a custom column, use following

 

= [s=Text.Middle([BOD PDF filename],Text.PositionOf([BOD PDF filename],"BOD"),10),
r = try if Value.Is(Number.From(Text.End(s,7)), type number) then s else null otherwise null][r]

 

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test  

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsvMSTXUK0hJU4rVgfDinfxdDI2MTUzNzOMRMkBBczNTE2Mjw/i0zLzEHFQpUwjQMDLySszTRJZRio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"BOD PDF filename" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each [s=Text.Middle([BOD PDF filename],Text.PositionOf([BOD PDF filename],"BOD"),10),
r = try if Value.Is(Number.From(Text.End(s,7)), type number) then s else null otherwise null][r])
in
    #"Added Custom"

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

In a custom column, use following

 

= [s=Text.Middle([BOD PDF filename],Text.PositionOf([BOD PDF filename],"BOD"),10),
r = try if Value.Is(Number.From(Text.End(s,7)), type number) then s else null otherwise null][r]

 

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test  

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsvMSTXUK0hJU4rVgfDinfxdDI2MTUzNzOMRMkBBczNTE2Mjw/i0zLzEHFQpUwjQMDLySszTRJZRio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"BOD PDF filename" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each [s=Text.Middle([BOD PDF filename],Text.PositionOf([BOD PDF filename],"BOD"),10),
r = try if Value.Is(Number.From(Text.End(s,7)), type number) then s else null otherwise null][r])
in
    #"Added Custom"

 

Thank you so much!! 👍

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.