Expression.Error: There weren't enough elements in the enumeration
By Tahir Nas · Examples run in our simulator · Published · Updated
Expression.Error: There weren't enough elements in the enumeration to complete the operation.
Code asked for a list item or table row that doesn't exist, such as {0} on an empty list or Table.First of an empty table used later.
Common causes
- Positional access {0} on an empty list.
- A filter removed every row before a step that takes the first row.
- Splitting text that has fewer parts than expected.
How to fix it
- Check List.IsEmpty or Table.IsEmpty before positional access.
- Use List.First(list, default) with a default value.
- Use the optional ? operator: list{0}? returns null instead of an error.
Find the step that fails
- Open the query in the Power Query editor (Excel: Data → Queries & Connections → Edit; Power BI Desktop: Transform data).
- Click the steps in Applied Steps from the top. The first step that shows the error is where it starts; later steps only repeat it.
- Read that step's formula in the formula bar (View → Formula Bar if it's hidden) and compare it with the columns and values the previous step produced.
Minimal example
Raises the error:
{}{0}Fixed:
{}{0}?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
- intermediate~9 minPro
Build a one-row summary table in M (kite shop)
Write a let expression that computes order count, total quantity and the largest unit price, returned as a one-row table.
- intermediate~9 minPro
Build a calendar from the first to the last order date (kite shop)
Create a table with one row for every day from the earliest to the latest order date, including days with no orders.
- beginner~6 minPro
Turn a settings object into a Name/Value table (report config)
A JSON settings file is a single object. List its settings as rows with Name and Value columns.
- intermediate~7 minPro
Find customers who ordered in January but not in February (kite shop)
Compare the customer lists of two months and return the customers who didn't come back.