Text.TrimEnd
Removes spaces from the end of a text value only.
Text.TrimEnd(text as nullable text, optional trim as any) as nullable textReturns: The text with its trailing spaces removed, or null when the input is null.
What it does
Fixed width exports, such as older bank and payroll files, pad every field to a set width with spaces. A short name arrives with a long tail of spaces that makes it look different from the same name typed by hand. Text.TrimEnd removes that tail and leaves the start of the value alone.
Syntax and arguments
- text: the value to clean.
- trim (optional): a character or list of characters to remove from the end instead of spaces, for example a trailing "*" or "/".
Example
A bank sends a fixed width file where the payee name always occupies 30 characters. The finance team wants the payee name clean for the cash application table.
let
Raw = "Harbor Freight Supply ",
Clean = Text.TrimEnd(Raw),
Length = Text.Length(Clean)
in
{Clean, Length}
The name comes back as "Harbor Freight Supply", which has 21 characters. The leading characters are unchanged, so the cleaned value still starts exactly where the bank put it.
Example: a second, different use
Remove a trailing asterisk that a system adds to marked items: Text.TrimEnd("Ledger Adj*", "*") returns "Ledger Adj".
Things to watch
- It does not touch the start. Use Text.Trim when both sides carry junk.
- If a value still fails to match after trimming, check it with Text.Length. A hidden character may be the cause.
- Trimming before you compare is safer than comparing padded values and hoping the match works.
- A null in gives a null out.
In business terms
Fixed width bank and payroll files arrive padded, and the padding breaks matches on payee and employee names. Trimming the end of each field is usually the first cleanup step after the file is loaded.