Forum Discussion
Power Query - Remove last two characters from a column
- 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"}) - 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
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
- Interkoubess8 years agoSolution 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
- Anonymous8 years agoNot applicableThank you for multiple helpfuö answers!
- sarverha5 years agoRegular Visitor
Interkoubess I stumbled across this post when trying to create a new column in power Query that remove the last digit of a string if it begins with 9.
For example 9396920 would be 939692 but 2020010 would remain the same.
I wrote this to identify if the column begins with 9.Text.StartsWith([Custom],"9")
but when I try to conbine with the solution below, I get an error message.
Text.Start([column];Text.Length([column])-2)
Help would be much appreciated.
- macmy0343 years agoResolver I
For anyone who found this and wonders why its an error; The original user uses semicolons instead of commas for formulas - Replace ; with , and it will work.