Text.Trim

Text

Removes leading and trailing whitespace (or specified characters) from a text value.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

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

Parameters

NameTypeRequiredDescription
texttextYesThe text value to trim.
trimanyNoA single character or list of characters to trim. Defaults to whitespace.

Return Value

textThe text with leading and trailing whitespace or specified characters removed.

Remarks

Text.Trim removes leading and trailing whitespace from a text value. Pass a character or list of characters as the second argument to trim specific characters instead of whitespace.

This is one of the most common data-cleaning operations, useful for fixing imported text that has extra spaces.

Examples

Example 1: Trim whitespace from product names

Table.TransformColumns(
    Table.SelectColumns(Table.FirstN(Sales, 3), {"Product"}),
    {"Product", Text.Trim, type text}
)
Result
Product
1Widget A
2Gadget B
3Widget C

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks