List.Repeat
Repeats a list a set number of times and joins the copies into one list.
List.Repeat(list, count)Returns: A list made of the original items, repeated.
What it does
List.Repeat makes copies of a list and joins them end to end. The usual finance uses are a placeholder column of the same value, such as a zero for twelve months of an unpopulated budget, or a fixed repeat of a standard row before the real data is added.
Syntax and arguments
list: the items to repeat, as one block.count: how many copies to make.
Example
A new cost center has no budget yet. The planning model needs twelve months, each set to zero, until the owner sends numbers.
let
PlaceholderBudget = List.Repeat({0}, 12),
Total = List.Sum(PlaceholderBudget)
in
Total
PlaceholderBudget holds twelve zeros, and the total is zero. When real figures arrive, the placeholder is replaced, and the rest of the query does not change.
Example: a second, different use
Repeating a pattern of two items: List.Repeat({"Debit", "Credit"}, 3) returns six items in alternating order, which is handy for building a sample test file.
Things to watch
- The block is repeated as a whole.
List.Repeat({1, 2}, 3)gives 1, 2, 1, 2, 1, 2, not 1, 1, 1, 2, 2, 2. - Repeating a list does not give you separate rows in a table. Use it to build the list, then convert the list to a table.
- A placeholder value is easy to forget. Put a note in the query, so a zero is not mistaken for real budget later.
- Count must be a whole number of zero or more.
In business terms
Placeholder budgets, default values for new entities, sample test data and a fixed number of blank periods in a template are typical uses. Make placeholders obvious, so they are not mistaken for actuals.