Text.Trim power query function

Text.Trim Power Query to remove spaces

Text.Trim power query function helps us to remove spaces from the beginning and end of the given string. It also helps to remove a particular character from both ends of the string.

Syntax

Text.Trim(Given String, Character that you want to remove(Optional))

It takes two parameters.

  • The first parameter is the given string.
  • The second parameter is optional, in which you have provided the character that you want to remove.

Text.Trim Power Query Example 1

Let’s take the following example: we have a couple of account numbers with spaces at the start and end.

Account dataset

Now we have to write the following power query formula.

Text.Trim([Account])

If you want to remove the spaces, then no need to provide a space as an optional parameter, as you can see below.

We will get the following result.

If you see the last account number, “000ABC00,” we have no spaces at the beginning and end, but we have some zeros on both ends.

Now we need to write Text.Trim power query function to remove zeros from both sides of account no.

Text.Trim([Account],"0")
Text.Trim power query function

If you look at the output, only the last account number, “000ABC00,” is affected, but the rest of the accounts still have zeros. It happens because of spaces.

First, we need to remove spaces, and then we must remove zeros. Let’s write the following formula to get clean results.

Text.Trim(Text.Trim([Account]),"0")
Nested Text.Trim power query function

We will get the following result.

Clean results after applying nested Text.Trim function

To learn more, please visit Learn DAX

Similar Posts