Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Power Query - Remove last two characters from a column

Hi,   Simple question. How to remove last two characters from each field of the column, i.e. replicate Excel's LEFT("column";LEN(column)-2) in M language?   Thanks!
  • stretcharm's avatar
    8 years ago

     

    Use Split

     

    Right mouse on col, select split, then by char by position. Enter 2 and pick once from right. You'll get 2 columns so delete the one you don't want.

     

    The M /Power Query code looks like this.

     

    = Table.SplitColumn(#"Removed Columns1", "Field", Splitter.SplitTextByPositions({0, 2}, true), {"Field.1", "Field.2"})

     

     

  • Interkoubess's avatar
    Interkoubess
    8 years ago

    Hi Anonymous,

     

    As explained you can use this formula in M:

    Text.Start([column];Text.Length([column])-2)

    That means your column is a text and it is not empty or null otherwise you need to add a condition...

     

    Hope it helps...

     

    Ninter