The TrimEnds function in Power Apps is used to remove any leading and trailing spaces from a string.
It helps clean up text input by eliminating unnecessary spaces at the beginning and end of the string, but leaves spaces between words intact.
If you specify a single-column table that contains strings, the return value is a single-column table of trimmed strings
Syntax:
TrimEnds(String)
String: Required, The text string from which leading and trailing spaces will be removed.
or
TrimEnds(SingleColumnTable)
String: Required. A single-column table of strings to remove spaces from.
Using TrimEnds function
Example 1:
TrimEnds(" Remove leading and trailing spaces ")
This formula will return “Remove leading and trailing spaces”. The spaces before and after the text are removed.
Example 2:
TrimEnds("Remove trailing spaces   ")
In this case, the TrimEnds function removes the trailing spaces after the text “Remove trailing spaces “ but does not affect any spaces within the string itself.
It will return “Remove trailing spaces”.
Example 3:
ClearCollect(
 colData_source,
 {Val: "Hello  "},
 {Val: "  There  "},
 {Val: " Learn Power Apps  "}
)
Now, run the app and click the button. A collection named colData_source will be created, containing 3 records.

Let’s use the TrimEnds function to remove spaces from the Val column while copying the updated records into another collection colData_target.
Now, add another button. Go to OnSelect property of button and write the below formula.
ClearCollect(
 colData_target,
 ForAll(
   colData_source,
   {Val: TrimEnds(Val)}
 )
)
Let’s run the App, and you can see it creates a new collection colData_target having the Val field cleaned of leading and trailing spaces.

Read Also..
- ForAll function in Power Apps
- Navigate function in Power Apps
- Launch function in Power Apps
- Table function in Power Apps
![]()
