List.Skip
Returns a list with the first items removed, either a set number or the run of items at the start that pass a test.
List.Skip(list, optional countOrCondition)Returns: The rest of the list, after the skipped items.
What it does
List.Skip removes items from the front of a list and returns what is left. The most common use is removing a header or an opening balance that was included by accident. It is the opposite of List.FirstN. If you give no count, it skips one item.
Syntax and arguments
list: the list to work on.countOrCondition(optional): how many items to skip. The default is 1. You can also pass a function that skips items from the start while the test is true.
Example
A text export puts a title line before the amounts. The first item is the title, and the amounts should be totalled without it.
let
ExportLines = {"Amount (USD)", "1250.00", "480.00", "75.00"},
Amounts = List.Skip(ExportLines, 1),
Numbers = List.Transform(Amounts, Number.FromText),
Total = List.Sum(Numbers)
in
Total
Amounts drops the title, so Total is the sum of 1250, 480 and 75, which is 1805. Without the skip, Number.FromText would fail on the title line.
Example: a second, different use
Skipping the opening balance and keeping the movements: List.Skip(Steps, 1) removes the seed from a running balance list built with List.Accumulate.
Things to watch
- Skip removes items from the start only. To remove the end, take the items you want with List.FirstN, or remove rows from the end of a table with Table.RemoveLastN.
- Skipping more items than the list holds returns an empty list, not an error. Check with List.Count afterward.
- For a table, the same idea is Table.Skip, which removes rows from the top.
- Check the source before you skip. If a refresh adds a line above the header, a fixed count will skip the wrong line.
In business terms
Removing title rows from bank and system exports, dropping an opening balance from a running total and skipping a header in a list of amounts all use this function. Note the number of items skipped in the workpaper, so the removal can be checked.