Text.Middle Function in Power Query

The Text.Middle function returns the substring offset by the start index and up to a specific length.

Syntax

Text.Middle(text as nullable text, start as number, optional count as nullable number) as nullable text

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

Example: Get the text starts from the index 5 and returns only 7 characters in the output.

Power Query M

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

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

Handle Out of Range Issue In the Text.Middle function if we have specified the count of characters which would be returned more than the resultant text, then it will not throw an error, unlike Text.Range function which throws an error.

Example: Out of Range in Text.Middle function

Power Query M

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

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