List.Range
Returns a section of a list, starting at a position and running for a number of items.
List.Range(list, offset, optional count)Returns: A list with the chosen items, in order.
What it does
List.Range cuts out a middle section of a list. You give a starting position (counting from zero) and how many items to take. Use it to pull one quarter out of a twelve-month list, or a fixed block of rows from a report that repeats in sections.
Syntax and arguments
list: the list to cut from.offset: the position of the first item to keep. The first item is at position 0.count(optional): how many items to keep. Without it, the rest of the list is returned.
Example
A budget list holds twelve monthly amounts from January to December. The second quarter, April to June, is needed for a quarterly variance report.
let
MonthlyBudget = {100, 105, 110, 120, 125, 130, 135, 140, 145, 150, 155, 160},
SecondQuarter = List.Range(MonthlyBudget, 3, 3),
QuarterTotal = List.Sum(SecondQuarter)
in
QuarterTotal
Position 3 is April, the fourth item. Taking three items gives April, May and June: {120, 125, 130}, and the total is 375.
Example: a second, different use
Getting the rows after a header: List.Range(Lines, 1) returns everything from the second item onward, the same as List.Skip with 1.
Things to watch
- Positions start at zero. The fourth item is at position 3, which is the most common mistake.
- Check the list length before you cut a fixed section. A section that runs past the end of a shorter list gives you fewer items than you expected.
- A quarter or month that depends on a fixed position will break if the list changes length. Filter by date when you can.
- For rows of a table, Table.Range does the same job.
In business terms
Quarter slices of a monthly budget, a block of periods for a comparison and the rows for one section of a long export are typical uses. Pair the slice with the period labels, so the report is clear about which months it covers.