Smart Systems for Home

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

Power Query List.Range Function: How to Extract a Subset of a List

· 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

The List.Range function in Power Query extracts a contiguous subset of elements from a list, starting at a specified position and returning a given number of items. It is essential for filtering data dynamically when you need only a portion of a list, such as the first 10 rows or items 5 through 15. No setup is required beyond having a list in Power Query—this function works natively in the Power Query M language.

What You'll Need

  • A list of values in Power Query (e.g., a column of numbers, text, or dates)
  • Power Query Editor open in Excel, Power BI, or another supported platform
  • The starting index position (zero-based) and count of items to extract

Step-by-Step

  1. Open Power Query Editor by selecting Data > Get & Transform Data > Edit Query in Excel, or by clicking Transform Data in Power BI.
  2. Ensure your data is in list form. If your data is in a column, right-click the column header and select Remove Other Columns to isolate it, then click the column header again and choose Transform > To List. This converts the column into a list object.
  3. Open the Advanced Editor by selecting View > Advanced Editor from the top menu.
  4. Locate the line where your list is defined. It will look like Source = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} or similar.
  5. Below the list definition, add a new line using the List.Range function. For example, to extract items 2 through 5 (indices 2, 3, 4, 5), write: ExtractedRange = List.Range(Source, 2, 4). The first number is the starting index (zero-based), the second is the number of items to take.
  6. Press Done to apply the changes. The new step will appear in the Applied Steps pane on the right.
  7. Click on the new step (ExtractedRange) to view the result in the data preview pane. You should now see only the subset of the list you selected.
  8. To convert the result back into a table column, right-click the list in the preview and select Convert to Table, then click the double-arrow icon next to the column header to expand into separate rows.
  9. Click Close & Load to return the data to your worksheet or report.

Common Mistakes

  • Using a 1-based index instead of zero-based—starting at index 1 gives you the second item, not the first. Always count from 0.
  • Requesting more items than exist in the list (e.g., asking for 15 items when the list has only 10). This returns only the available items without error, which may cause unexpected results.
  • Passing a negative number for the count parameter, which causes an error. The count must be zero or positive.
  • Applying List.Range to a table instead of a list. The function only works on list objects—convert tables to lists first using Transform > To List.
  • Forgetting to name the new step. While optional, naming improves readability and debugging.

Tips

  • Use List.Count(Source) to dynamically determine the list length if you want to extract from the end. For example, List.Range(Source, List.Count(Source) - 5, 5) gets the last 5 items.
  • Combine List.Range with List.Positions() to generate dynamic index sequences for filtering based on conditions.
  • Use List.Range in conditional logic with if statements: if List.Count(Source) > 10 then List.Range(Source, 0, 10) else Source to avoid errors on short lists.
  • Test your range with a small sample list first (e.g., {1..10}) to verify behavior before applying to large datasets.
  • Use the Formula Bar (View > Formula Bar) to type List.Range directly instead of editing the Advanced Editor if you’re more comfortable with visual steps.

Troubleshooting

  • Error: “We couldn't convert to list” — Your input isn’t a list. Confirm the column was converted to list using Transform > To List. If you’re referencing a table column, use Table.Column(TableName, "ColumnName") to extract it as a list first.
  • Result is empty — You likely requested a range beyond the list’s bounds. Check that start + count does not exceed List.Count(Source). Use List.Count to validate length.
  • Function returns an error — Check for typos in the function name (List.Range, not ListRange or list.range). M is case-sensitive.
  • Unexpected items returned — Verify the index is zero-based. The first item is index 0, not 1. Double-check your start and count values.
  • Step disappears after refresh — Ensure your source data hasn’t changed structure. If the original column was deleted or renamed, the list reference breaks. Reapply the To List step or update the source reference.

Frequently Asked Questions

Can List.Range handle text lists?

Yes, it works with any data type: numbers, text, dates, or even records. Example: List.Range({"A", "B", "C", "D"}, 1, 2) returns {"B", "C"}.

What happens if I use a negative start index?

It causes an error. The start index must be zero or a positive integer. Negative values are not supported.

Can I use List.Range to get the last N items without knowing the list length?

Yes. Combine it with List.Count: List.Range(Source, List.Count(Source) - N, N) returns the final N items.

Is List.Range faster than filtering with conditions?

For extracting contiguous subsets by position, yes—it’s more efficient than filtering by value. But if you need to filter by criteria (e.g., values greater than 5), use List.Select instead.

Does List.Range work with nested lists?

It works on the top-level list only. If your list contains sublists, List.Range extracts sublists as elements, not their contents. You’d need List.Transform to drill deeper.

Can I use List.Range in a custom column?

Yes, but only if the list you’re referencing is available in the current row context. Most often, you’ll use it in a standalone step on a full list, not per-row.