Text.TrimEnd Power Query to remove spaces from the end of string

Text.TrimEnd power query function helps us to remove spaces or any character from the end of the given string. It comes under the category of power query Text functions. It is a very helpful function for data cleaning.

Syntax

Text.TrimEnd(Given String, which character do you want remove (optional)

It takes two parameters.

  • The first parameter is the given string.
  • The second parameter is optional. Here you have to provide which character, do you want to trim.

Text.TrimEnd Power Query Example

We have some account numbers with additional spaces at the end, as you can see below.

dataset account numbers

Under the “Clean Accounts” column, you can see some accounts. If you look closely for account no. “VR8900 ” there are some spaces that we need to remove.

Let’s write the following formula.

Text.TrimEnd([Clean Acconts])

We will get the following result.

The “Custom” column doesn’t have spaces at the end of any account. If you want to remove the spaces at the end then we don’t need to use the optional parameter in the Text.TrimEnd power query function.

If we try to use the following function to remove zeros from the end of the string that contains spaces at the end as well, then the following function will not work.

Text.TrimEnd([Clean Acconts],"0")

Because at the end of the string, there are no zeros, but we have spaces. So to remove zeros, we first need to remove spaces and, after that, zeros. It means we have to use Text.TrimEnd function two times.

Text.TrimEnd(Text.TrimEnd([Clean Acconts]),"0")
Text.TrimEnd Power query function

We will get the following result.

Text.TrimEnd result

To learn more, please visit Learn DAX

Similar Posts