Text.Trim
TextRemoves leading and trailing whitespace (or specified characters) from a text value.
Syntax
Text.Trim(text as nullable text, optional trim as any) as nullable textParameters
| Name | Type | Required | Description |
|---|---|---|---|
text | text | Yes | The text value to trim. |
trim | any | No | A single character or list of characters to trim. Defaults to whitespace. |
Return Value
text — The 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 | |
|---|---|
| 1 | Widget A |
| 2 | Gadget B |
| 3 | Widget C |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks