Updated on

Text.TrimEnd is a Power Query M function that removes trailing whitespace from a text value. The function returns the modified text value with the trailing whitespace removed.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365


   text as nullable text,
   optional trim as any,
) as nullable text


Returns the result of removing all trailing whitespace from text value text.


The Text.TrimEnd function in Power Query M is a trusted technique for eliminating unwanted characters from the ending of your text strings. We’ve curated a series of practical examples to showcase the powerful utility of the Text.TrimEnd function.

The most straightforward use case for this function is to remove trailing whitespace from a text string. When the second argument is not provided, the function defaults to trimming whitespace characters.

For instance, consider the string ” a b c d “. With Text.TrimEnd, we can strip the trailing spaces:

Text.TrimEnd( "   a b c d    " ) // Returns "   a b c d"

In addition to spaces, you can instruct the function to remove any character from the end of a string. By specifying this character in the second argument, the function will only remove that particular character.

For example, the text “**gorilla**” has asterisks at both ends, but if you want to remove the asterisks only at the end, you would do as follows:

Text.TrimEnd( "***gorilla***", "*" ) // Returns "***gorilla"

There may be situations where you need to remove multiple different characters from the end of a string. In these cases, the function can accept a list of text values in the second argument, indicating the characters to be removed.

To illustrate, let’s say we want to get rid of both spaces and asterisks from “gorilla * *”. Passing both ” ” and “*” in a list to Text.TrimEnd does the job perfectly:

Text.TrimEnd( "gorilla * *", { " ", "*" } ) // Returns "gorilla"

You can even provide Text.TrimEnd with a generated list to strip all lowercase letters from the end of a string:

Text.TrimEnd( "pizzaHut", { "a" .. "z" } ) // Returns "pizzaH"

Learn more about Text.TrimEnd in the following articles:

Other functions related to Text.TrimEnd are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/text-trimend