Power QueryExercises

Expression.Error: The 'count' argument is out of range

By Tahir Nas · Examples run in our simulator · Updated

Expression.Error: The 'count' argument is out of range.

Text.Range or Text.Middle asked for more characters than the text has from that offset. Fixed-position extraction breaks as soon as one value is shorter than expected.

Common causes

How to fix it

  1. Use Text.Middle, which returns what's available when the count runs past the end.
  2. Prefer delimiter-based functions: Text.AfterDelimiter, Text.BetweenDelimiters.
  3. Check Text.Length first for a default value.

Find the step that fails

Minimal example

Raises the error:

Text.Range("AB-12", 3, 5)

Fixed:

Text.Middle("AB-12", 3, 5)

Both snippets are run by the Power Query Exercises simulator on every build: the first must raise Expression.Error, the second must run.

Practise avoiding it

Guides

Related lessons

Similar errors