Forum Discussion

rovers's avatar
rovers
Frequent Visitor
4 years ago
Solved

Extracting substrings from free text

Hi, Seeking help to code the following in Power Query (preferred) or DAX.   Input Table: ID; Free Text Order123; PN113 and PN224 were used to fulfil the order. However, there was no stock of PN1...
  • lbendlin's avatar
    4 years ago

    Here is a crude way of doing this. It assumes that the string "PN"  does not appear anywhere else in the text. So "The driver was hypnotized"  wouldn't work.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY47DoMwEESvMqK2kACTM6QiFHSIwoK1QFjeyB+4fmyS0O7OvDfjWLzcQq6qm0IUfVdVDZRd0Hd1LXGSI0RPCwJDR6M3g7ASOFdKPPmkg5zItxQ8lYdl+MDzDta4aOUflZ68l8UkbqNMxuFuKovN+0i5IGX7owVojnYpMTAceTZHHrNuXqRY2z6u2LVws3gbNdPXnAjJNX0A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Free Text" = _t]),
        #"Replaced Value" = Table.ReplaceValue(Source,"."," ",Replacer.ReplaceText,{"Free Text"}),
        #"Added Custom1" = Table.AddColumn(#"Replaced Value", "Custom.1", each List.Distinct(List.FindText(Text.Split([Free Text]," "),"PN"))),
        #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1")
    in
        #"Expanded Custom.1"