Power QueryExercises

Text.Trim

Text function · By Tahir Nas · Examples run in our simulator · Published · Updated

Removes leading and trailing whitespace.

When to use it

Use it on every text key and category column straight after import, before filters, merges or duplicate checks. Leading and trailing spaces are the most common reason values that look equal don't match.

Syntax

Text.Trim(text as nullable text, optional trim as any) as nullable text

Parameters

trim
Optional characters to trim instead of whitespace.

Returns

The trimmed text.

Example

Text.Trim("  North ")

Result

North

Example: trim other characters

The optional argument lists characters to remove from both ends.

Text.Trim("--A-17--", "-")

Result

A-17

Both results are produced by the Power Query Exercises simulator, an independent implementation of a documented subset of M, and checked on every build.

Good to know

Common mistakes

The matching command in Excel

Excel for Windows
Transform > Format > Trim (Add Column > Format > Trim keeps the original)
What you see
The command runs on every value of the selected text column.

Paths are for the Power Query editor in Excel for Microsoft 365, checked against Microsoft's documentation on 8 November 2026: Add a column based on a data type (Power Query) (Microsoft Support).

Exercises that use Text.Trim

Learn more

Related functions

Official documentation: Text.Trim on Microsoft Learn.