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
Syntax
Text.TrimEnd(
text as nullable text,
optional trim as any,
) as nullable text
Description
The Text.TrimEnd
function removes unwanted characters from the end of a text string. By default, it trims whitespace, but it can also remove specific characters or a list of characters when specified.
Examples
Here are some practical examples to learn how Text.TrimEnd works.
Removing Trailing Whitespace
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"
Removing Specific Characters
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"
Removing Multiple Characters
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"
Removing a Range of Characters
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"
Related articles
Learn more about Text.TrimEnd in the following articles:
- Text Functions in Power Query M (150+ Examples)
Your guide to Text Functions in Power Query M. Learn from practical examples and master Power Query’s most useful Text functions. » Read more
Related functions
Other functions related to Text.TrimEnd are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy