Forum Discussion
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!
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"})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
8 Replies
- stretcharmMemorable Member
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"}) - jthomsonSolution Sage
Text.Length is the M equivalent to LEN, if you use that in combination with Text.RemoveRange you should be able to do what you want
- InterkoubessSolution Sage
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
- AnonymousNot applicableThank you for multiple helpfuö answers!