Text.Range

Text

Returns a substring from a text value starting at a given offset, optionally limited to a specified number of characters.

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

Syntax

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

Parameters

NameTypeRequiredDescription
texttextYesThe source text value.
offsetnumberYesThe zero-based starting position.
countnumberNoThe number of characters to return. If omitted or null, returns all characters from offset to end.

Return Value

textThe substring of text starting at offset for count characters, or to the end of the string if count is omitted.

Remarks

Text.Range returns a substring from text starting at the zero-based offset index. If count is provided, at most count characters are returned. If count is omitted or null, all characters from offset to the end of the string are returned.

If text is null, the function returns null. If offset is beyond the end of the string, an empty string is returned — not an error. If count extends beyond the available characters, all remaining characters are returned without error. This lenient boundary behavior makes Text.Range safe to call without pre-checking string length, though you should still validate that the returned value is not empty when presence of content is expected.

Text.Range and Text.Middle are functionally identical — both accept an offset and optional count. Text.Range tends to appear in manually written queries where "range" feels more natural, while Text.Middle is the name produced by the Power Query UI. Choose based on readability in context.

For extracting the beginning of a string, Text.Start is more expressive. For extracting from the end, use Text.End. For a single character, use Text.At. Use Text.Range or Text.Middle when you need to extract from the interior of a string.

Examples

Example 1: Extract from an offset to the end of the string

Text.Range("Marketing Lead", 10)
Result
Result
1Lead

Example 2: Extract a fixed-length substring from a structured code

Text.Range("2024-03-15", 5, 2)
Result
Result
103

Example 3: Extract the year from a hire date stored as text

Text.Range("2021-03-15", 0, 4)
Result
Result
12021

Example 4: Extract the numeric part of an employee ID

Text.Range("E001", 1, 3)
Result
Result
1001

Compatibility

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