Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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 ...
  • Vijay_A_Verma's avatar
    4 years ago

    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"