Forum Discussion

ngct1112's avatar
ngct1112
Post Patron
5 years ago
Solved

PowerQuery - Text before multiple Delimiters

Hi,

 

May I know is there any way I could split text before multiple Delimiters in one function?

Original ColumnDesired Result
1 & 51
50 - 100050
1000/20001000
2000&50002000
5000/100005000

 

Great thanks!

  • Add a step to extract the text before one of those delimiters, and then modify the code in the formula bar to look like this

     

    = Table.TransformColumns(Source, {{"Column1", each Text.Start(_, Text.PositionOfAny(_, {"&", "/", "-"})), type text}})

     

    Pat

5 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    Add a step to extract the text before one of those delimiters, and then modify the code in the formula bar to look like this

     

    = Table.TransformColumns(Source, {{"Column1", each Text.Start(_, Text.PositionOfAny(_, {"&", "/", "-"})), type text}})

     

    Pat

    • doubleclick's avatar
      doubleclick
      Resolver I

      how can this be done with a multiple character string?

    • Travis_rh's avatar
      Travis_rh
      Frequent Visitor

      mahoneypat ,

      Two follow-on questions:

      1. How might I add null handling? It seems that Power Query returns an error if it doesn't find any of the specific delimiters.
      2. How would I extract the text after the first space OR after the first "-"? I used Text.Middle instead of Text.Start which works for the space, but still includes the "-" in the extracted text. 

      Thank you,

       

      -Travis

    • Joris_NL's avatar
      Joris_NL
      Helper III

      In case other people struggle with changing the 'text before delimiter' line into TransformColumns, like I did, here is some clarification: 

       

       

      = Table.TransformColumns(#"NameOfPreviousQueryStep", {{"Original column you want to edit", each Text.Start(_, Text.PositionOfAny(_, {"&", "/", "-", "any other symbols"})), type text}})

       

       

      So don't expect to create a new column!