The TrimEnds function is one handy function that is often confused by the Trim function since it works closer to the way developers are used to it. This function will only trim spaces at the beginning and the end of the string. If there are extra spaces in the string, they are not changed. In contrast, the Trim function will remove all extra spaces making some people confused. Let’s explore it further to understand how it works.
It follows a simple pattern.
Let’s build a simple Power App that has a text input and a text label with the result of the trim. It will allow us to test a bunch of cases and see the result. The formula will always be the same:
Let’s start with the simplest case. No spaces in the beginning or end:
The result is what we expect. There aren’t any spaces to remove, so the string remains the same. Now let’s add some spaces.
The function removes the spaces without interfering with the ones inside the string. Awesome.
Let’s add a few lines and see if it removes the lines’ carriage return.
Nothing is changed, so we’re good. What about an empty string, or one with only spaces?
The function removes the spaces and returns a string empty, so the formula accepts empty spaces.
Let’s try one last test if we have extra spaces in the string.
If you’re a developer, this is what you’re used to. Using the Trim function instead of this one is a common mistake, so be careful and understand the difference between both.
- This function is never delegable, so be careful if you have an unusually large dataset. If you don’t know what this is, please check my article on delegation and my reference table of the data sources where Filter will be delegable. If not, the Power App will only display the first 500 values (default value up to 2000).
- If you want to remove all extra spaces at the beginning, end, and inside the string, you should use the “Trim” function. Most programming languages treat the Trim as the TrimEnds in Power Apps, so be aware of this distinction so as not to get invalid results.
- Don’t nest the function. It’s not necessary since it always returns the same value.
TrimEnds function in Power Apps
Back to the Power Apps Function Reference
Photo by Mark Tegethoff on Unsplash