Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query List.RemoveFirstN: How to Use It

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

List.RemoveFirstN removes a specified number of items from the start of a list in Power Query. It is a built-in M function that returns a new list, leaving the original unchanged. Use it when you need to drop header rows, skip metadata lines, or trim a list to its meaningful content. You can call it directly in a custom column or use the equivalent Remove First N Items button in the Power Query Editor ribbon.

What You'll Need

  • Power Query available in Excel (Data > Get & Transform Data) or Power BI Desktop (Transform Data).
  • A query that produces a list, or a table column you can convert to a list.
  • Basic familiarity with the Power Query Editor and its formula bar.

Step-by-Step

  1. Open the Power Query Editor. In Excel, go to Data > Get & Transform Data > Launch Power Query Editor. In Power BI Desktop, click Transform Data on the Home ribbon. Menu labels can differ slightly by version, device or region.
  2. Load or create the list. If your data is already a table, select the column that contains the list values. To turn a column into a list, right-click the column header and choose Drill Down (or use the Transform tab > Convert to List).
  3. Locate the formula bar. If it is hidden, enable it from the View tab. The formula bar shows the current step's M code.
  4. Write the function call. In the formula bar, replace the current step with a call to List.RemoveFirstN. The syntax is List.RemoveFirstN(list as list, optional countOrCondition as any) as list. For example, to remove the first three items from a list named MyList, use List.RemoveFirstN(MyList, 3).
  5. Use the optional condition form. Instead of a number, you can pass a condition such as each _ < 10. The function then removes items from the start of the list as long as the condition is true. For example, List.RemoveFirstN({1, 2, 15, 3}, each _ < 10) returns {15, 3} because it stops removing once it hits 15.
  6. Press Enter to commit the step. Power Query evaluates the expression and shows the resulting list. If the step name is generic, rename it in the Applied Steps pane for clarity.
  7. Alternatively, use the ribbon button. Select the list column, then on the List Tools / Transform tab, click Remove First N Items. A dialog appears where you enter the number. This generates the same M code for you.
  8. Expand or convert the result. If you need the list back as a table column, use List.ToTable or click To Table on the Transform tab. Then expand the column to see the remaining items.
  9. Close and load. When the query looks correct, click Close & Load (Excel) or Close & Apply (Power BI) to send the result to your worksheet or data model.

Common Mistakes

  • Passing a number larger than the list length. List.RemoveFirstN returns an empty list if the count exceeds the number of items. It does not error, but you may not notice the data is gone.
  • Forgetting that the original list is unchanged. The function returns a new list; it does not modify the source. You must use the returned value in subsequent steps.
  • Using a negative number. The count must be zero or positive. Negative values cause an error.
  • Confusing the condition form with a filter. The condition form only removes items from the start while the condition is true; it does not filter the entire list.
  • Assuming the count is one-based. The count is the number of items to remove, not an index. Removing 1 item removes the first element, not the second.

Tips

  • Use List.RemoveFirstN together with List.Count to check how many items remain: List.Count(List.RemoveFirstN(MyList, 2)).
  • For removing items from the end, use List.RemoveLastN with the same syntax.
  • If you need to remove items based on their position and value, combine List.PositionOf with List.RemoveFirstN.
  • Keep a step that shows the original list count so you can compare before and after.
  • When working with table columns, consider using Table.Skip instead of converting to a list and back.

Troubleshooting

  • Error: "We cannot convert a value of type ... to type List." The first argument is not a list. Check that you are passing a list, not a table or a single value. Use List.From or convert the column to a list first.
  • Error: "The count must be a non-negative number." You passed a negative count. Use zero or a positive integer.
  • The result is empty when you expected items. The count is larger than the list length. Reduce the count or check the list size with List.Count.
  • The condition form removes more than expected. The condition is evaluated from the start and stops at the first item that fails. Verify the condition logic with a small sample list.
  • The step does not appear in Applied Steps. If you edited the formula bar directly, the step may have been overwritten. Use the Advanced Editor to inspect the full M code and ensure the step is included.
  • Performance is slow on very large lists. List.RemoveFirstN is efficient, but repeated list operations in a custom column can add up. Consider filtering earlier in the query.

Frequently Asked Questions

What does List.RemoveFirstN return if the count is zero?

It returns the original list unchanged.

Can I use a condition instead of a number?

Yes. Pass a condition such as each _ < 10 as the second argument. The function removes items from the start while the condition is true.

Does List.RemoveFirstN modify the original list?

No. It returns a new list. The original list remains unchanged.

What happens if the count is greater than the number of items?

It returns an empty list.

Is there a ribbon button for this function?

Yes. Select a list column, then on the List Tools / Transform tab, click Remove First N Items. The button generates the M code for you.

Can I remove items from the end of a list?

Yes. Use List.RemoveLastN with the same syntax.