Text.RemoveRange Function in Power Query
The Text.RemoveRange function in Power Query is used to remove a range of characters from the given text string, starting at a specified position and for a specified length.
Syntax
Text.RemoveRange( text as nullable text, offset as number, optional count as nullable number ) as nullable text
The function has the following parameters:
- text: The input text string.
- offset: The zero-based position at which to start removing characters. If this is greater than the length of the string, it throws an error stating “The 'offset' argument is out of range”.
- count: It is an optional parameter. The number of characters to remove. If not specified, the default value is 1. If the count argument is greater than the number of characters available to remove, it throws an error stating “The 'count' argument is out of range”.
Returns: A new text value with the specified range of characters removed.
Example: Remove one character starting at position 2.
Power Query M
let Source = Text.RemoveRange("Ashish Coder", 2, 1) in Source
The output of the above code is "Asish Coder".
Example: Offset out of range.
Power Query M
let Source = Text.RemoveRange("Ashish Coder", 50, 8) in Source
The output of the above code is:
Expression.Error: The 'offset' argument is out of range. Details: 50
Example: Count out of range.
Power Query M
let Source = Text.RemoveRange("Ashish Coder", 5, 8) in Source
The output of the above code is:
Expression.Error: The 'count' argument is out of range. Details: 8