Power Query List.RemoveRange: How to Delete Items
In this article
List.RemoveRange removes a block of items from a Power Query list, starting at a position you specify and deleting the number of items you ask for. The syntax is List.RemoveRange(list as list, index as number, count as number) as list, where index is the zero-based starting position and count is how many items to delete. It returns a new list and leaves the original untouched, so you can chain it inside a query without side effects. You need a list to work on and access to the Power Query Editor, which ships with Excel and Power BI Desktop.
What You'll Need
- A version of Excel or Power BI Desktop with the Power Query Editor (both include the full M language, so no add-in is required).
- A list value to operate on, either created in a query step or loaded from a column, table or text split.
- Basic familiarity with the Advanced Editor or the formula bar, since List.RemoveRange is written as an M expression rather than a ribbon button.
Step-by-Step
- Open the Power Query Editor. In Excel, select a cell in your data and choose Data > From Table/Range. In Power BI Desktop, choose Home > Transform data. Menu labels can differ slightly by version and region, but the Power Query Editor window itself is the same.
- Get a list into the editor. The simplest way is to create a blank query: choose Home > New Source > Blank Query, then open Home > Advanced Editor. Alternatively, convert an existing column to a list with a step such as
Table.Column(#"Previous Step", "ColumnName"). - Write a list literal to test with. In the Advanced Editor, replace the query with something like
let Source = {"a", "b", "c", "d", "e"} in Source. The curly braces create a list. Click Done. You should see five items in the result preview. - Add the List.RemoveRange step. Edit the query to
let Source = {"a", "b", "c", "d", "e"}, Removed = List.RemoveRange(Source, 1, 2) in Removed. Click Done. - Read the result. The output is
{"a", "d", "e"}. Index 1 is the second item ("b"), and count 2 deletes "b" and "c". This confirms the zero-based indexing: position 0 is the first item. - Replace the literal with your real list. Swap
Sourcefor the name of the step that produces your list, for exampleList.RemoveRange(MyList, 0, 3)to drop the first three items. - Check the count against the list length. Use
List.Count(MyList)in a temporary step if you are unsure how many items exist. If index plus count exceeds the list length, Power Query raises an error rather than silently trimming. - Apply and load. Once the preview shows the list you expect, choose Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to send the result back to your workbook or model.
Common Mistakes
Assuming one-based indexing. The most frequent error is passing 1 expecting to remove the first item. Index 0 removes the first item; index 1 removes the second. Off-by-one results are almost always this.
Confusing count with an end position. The third argument is how many items to delete, not the index to stop at. List.RemoveRange(MyList, 2, 3) deletes three items starting at position 2, ending at position 4.
Removing from a table instead of a list. List.RemoveRange only accepts a list. If you pass a table column reference without converting it, you get a type error. Wrap the column in Table.Column first.
Expecting the original to change. M is immutable. The function returns a new list; you must capture it in a new step or the change is lost.
Hard-coding positions on data that shifts. If rows are added or sorted upstream, fixed indexes remove the wrong items. Prefer filtering with List.Select when the rule is value-based rather than position-based.
Tips
Use List.RemoveRange together with List.FirstN and List.Skip when you need to keep a middle slice: skip the front, then remove the tail. For a single item, List.RemoveRange(MyList, n, 1) is clearer than building a filter. Name intermediate steps descriptively (for example TrimmedHeaderRows) so the Applied Steps pane stays readable. Test with a small literal list before pointing the function at live data; the preview updates instantly and errors are easier to spot. Remember that an empty list is valid input, and removing zero items returns the list unchanged.
Troubleshooting
"Expression.Error: The index is outside the bounds of the list." Your index is greater than or equal to the list length, or index plus count runs past the end. Check the length with List.Count and reduce the index or count.
"We cannot convert a value of type Table to type List." The first argument is a table, not a list. Convert the column with Table.Column or expand the list before calling the function.
The result looks unchanged. Confirm the step is actually referenced in the final in clause. An orphaned step still appears in Applied Steps but does not affect output.
Wrong items removed after a refresh. The source order changed. Replace positional logic with a value-based filter, or sort explicitly before removing so the index is predictable.
Nothing works after edits. Reopen the Advanced Editor and check for a missing comma between steps or an unclosed brace. If the query is badly broken, delete the last step from Applied Steps and rebuild it.
Frequently Asked Questions
Is List.RemoveRange zero-based?
Yes. Index 0 refers to the first item in the list, so List.RemoveRange(MyList, 0, 1) removes the first item.
What happens if count is larger than the remaining items?
Power Query returns an error because the range extends past the end of the list. Keep index plus count at or below List.Count.
Can I remove items from several positions at once?
Not in a single call. Call List.RemoveRange repeatedly, working from the highest index downward so earlier removals do not shift later positions.
Does it modify the original list?
No. It returns a new list. Assign the result to a step to keep the change.
Can I use it on a table column?
Yes, after converting the column to a list with Table.Column. The function itself only accepts lists.
What does count = 0 do?
It returns the list unchanged, which is useful when the number to remove is calculated and may be zero.