Text.Range
TextReturns a substring from a text value starting at a given offset, optionally limited to a specified number of characters.
Syntax
Text.Range(text as nullable text, offset as number, optional count as nullable number) as nullable textParameters
| Name | Type | Required | Description |
|---|---|---|---|
text | text | Yes | The source text value. |
offset | number | Yes | The zero-based starting position. |
count | number | No | The number of characters to return. If omitted or null, returns all characters from offset to end. |
Return Value
text — The 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 | |
|---|---|
| 1 | Lead |
Example 2: Extract a fixed-length substring from a structured code
Text.Range("2024-03-15", 5, 2)Result | |
|---|---|
| 1 | 03 |
Example 3: Extract the year from a hire date stored as text
Text.Range("2021-03-15", 0, 4)Result | |
|---|---|
| 1 | 2021 |