Text.RemoveRange

Text

Removes a specified number of characters from a text value starting at the given offset.

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

Syntax

Text.RemoveRange(text as nullable text, offset as number, optional count as nullable number) as nullable text

Parameters

NameTypeRequiredDescription
texttextYesThe original text value.
offsetnumberYesThe zero-based position at which to begin removing characters.
countnumberNoThe number of characters to remove. If omitted or null, all characters from offset to the end are removed.

Return Value

textA new text value with the specified characters removed.

Remarks

Text.RemoveRange removes count characters from text beginning at the zero-based offset position. The characters before offset and after offset + count are concatenated to form the result. The original string is not modified — a new value is returned.

If text is null, the function returns null. If count is omitted or null, all characters from offset to the end of the string are removed. If count extends beyond the length of the string, all characters from offset onward are removed without error.

This is equivalent to: Text.Start(text, offset) & Text.End(text, Text.Length(text) - offset - count)

Use Text.RemoveRange for positional removal — when you know the exact character position and length of the content to remove. If you want to remove by content (all occurrences of a substring), use Text.Replace(text, toRemove, ""). If you want to replace removed characters with new content rather than nothing, use Text.ReplaceRange.

Examples

Example 1: Strip a known prefix from a column

Text.RemoveRange("E001", 0, 1)
Result
Result
1001

Example 2: Remove a separator character at a known position

Text.RemoveRange("(555) 123-4567", 0, 1)
Result
Result
1555) 123-4567

Example 3: Remove everything from an offset to the end

Text.RemoveRange("Sales Rep - East Region", 9)
Result
Result
1Sales Rep

Example 4: Remove an internal segment from a formatted string

Text.RemoveRange("Widget-East-001", 6, 5)
Result
Result
1Widget-001

Compatibility

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