Downloads
Power Query MTextBeginner

Text.TrimEnd

Removes spaces from the end of a text value only.

Syntax
Text.TrimEnd(text as nullable text, optional trim as any) as nullable text

Returns: 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

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

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.

Related functions

All Power Query M functions · View as Markdown · M basics