Text.Range Function in Power Query

The Text.Range function returns the number of characters from a text value starting at a zero-based offset. An optional parameter, count, can be included to specify how many characters to return. Throws an error if there aren't enough characters.

Syntax

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

Note: The first character in the text has index 0.

Example: Get the text from index starting at 5.

Power Query M

let
    Source = Text.Range("Ashish Coder is the best website.", 5)
in
    Source 

The output of the above code is “h Coder is the best website.”.

Example: Get the text from index starting at 5, and in the returned text only 10 characters should be there.

Power Query M

let
    Source = Text.Range("Ashish Coder is the best website.", 5, 10)
in
    Source 

The output of the above code is “h Coder is”.

Note: Space is also counted as character.

Example: Out of Range issue in Text.Range function.

Power Query M

let
    Source = Text.Range("Ashish Coder is the best website.", 5, 100)
in
    Source  

The output of the above code throws an error Out of range.

Text.Range function in Power Query