Forum Discussion

Jackie003's avatar
Jackie003
Frequent Visitor
2 years ago
Solved

How to extract specific number of characters in Power Query

Hello, do you know how to extract specific number of characters from text?  The main rule is: if text contains CC then extract only 6 characters (as you can see on the picture) and if text con...
  • dufoq3's avatar
    dufoq3
    2 years ago

    Jackie003, you can try this. But I can only guess that you want to extract 6 or 18 characters after 1st space (you haven't mentioned this).

    Add this as Custom Column and replace [Column1] with your column reference

     

    [ a = Text.Trim([Column1]),
      b = Text.PositionOf(a, " ")+1,
      c = if Text.StartsWith(a, "CC")
          then Text.Range(a, b, 6) else
          if Text.StartsWith(a, "RECHARGE")
          then Text.Range(a, b, 18) else null
    ][c]