List.Repeat is a Power Query M function that creates a list containing a specified number of repetitions of the original list. The function returns the newly created list with the repeated elements.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
List.Repeat(
list as list,
count as number,
) as list
Description
The List.Repeat
function creates a new list by repeating the elements of a given list for a specified number of times. It takes two arguments: the list
of values to be repeated and the count
, which represents the number of repetitions. After performing the operation this function returns a single list with the values repeated consecutively.
Examples
Let’s look at a few examples of the List.Repeat function.
You can create a list that has {1, 2, 3 } repeated 3 times.
// Output: { 1, 2, 3, 1, 2, 3, 1, 2, 3 }
List.Repeat( { 1, 2, 3 }, 3 )
If you’re working on a mathematical or algorithmic problem, you might need to generate a sequence pattern. For instance, if you want a list that repeats the sequence 1 to 5 for 4 times:
// Output: { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 }
List.Repeat( List.Numbers( 1, 5 ), 4 )
The List.Repeat function also works with other values, like text. Suppose you’re categorizing items into groups, and you want to label each group with a repeated identifier. For example, if you have 15 items and you want to label them in groups of 5 with “Group A”, “Group B”, and “Group C”:
/* "Group A", "Group A", "Group A", "Group A", "Group A", "Group B", "Group B",
"Group B", "Group B", "Group B", "Group C", "Group C", "Group C", "Group C", "Group C" */
List.Combine(
{
List.Repeat( { "Group A" }, 5 ),
List.Repeat( { "Group B" }, 5 ),
List.Repeat( { "Group C" }, 5 )
}
)
These are just a few examples, but the potential applications are numerous. The function can be particularly useful when combined with other Power Query functions.
Related articles
Learn more about List.Repeat in the following articles:
- Lists in Power Query M / List Functions (200+ Examples)
The complete guide to Lists in Power Query M. Learn from practical examples and master Power Query’s most powerful List functions. » Read more
Related functions
Other functions related to List.Repeat are:
- List.Alternate
- List.FindText
- List.First
- List.FirstN
- List.Last
- List.LastN
- List.Max
- List.MaxN
- List.Min
- List.MinN
- List.Range
- List.Select
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy