konsama
konsama

Reputation: 347

Want to trim last (2) characters on a column of type text, is there a way to do this in the same column in Power BI?

I had searched for a solution and they all require creating another column, I want to know if there is a way to do it within the same column? I have DAX as well but just starting out on it so not as familiar with the abilities it has to offer.

Upvotes: 1

Views: 3585

Answers (1)

Alexis Olson
Alexis Olson

Reputation: 40204

You should be able to do it exactly the same way using Table.Transform rather than Table.AddColumns. In the GUI, just use the Transform tab instead of the Add Column tab.


In the GUI, go to Transform > Extract > First Characters and pick some value, say, 2. That should output a step with the code:

= Table.TransformColumns(#"Previous Step Name",
      {{"TextColumn", each Text.Start(_, 2), type text}})

This gives the first 2 characters but you want all but the last two. So replace 2 with Text.Length(_)-2 in the formula line to get Text.Start(_, Text.Length(_)-2).

If you prefer, Text.RemoveRange(_, Text.Length(_)-2, 2) should work too.

Upvotes: 4

Related Questions