Table.Repeat is a Power Query M function that repeats the rows in a table a specified number of times. The function returns a new table with the rows repeated according to the given count.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Table.Repeat(
table as table,
count as number,
) as table
Description
The Table.Repeat function duplicates a table a specified number of times, combining the repeated rows into one table.
Examples
Let’s see how the Table.Repeat functions works. Suppose we have a table called Source
that contains the following data:
If you want to repeat this table three times, the expression to use is:
Table.Repeat( Source, 3 )
This operation will output a new table where all the rows from the Source
table are repeated three times, one after another, in a single combined table. Here’s what the result would look like:
You could achieve the same result by manually concatenating the table with itself multiple times. Here’s an example using the concatenation operator:
Source & Source & Source
This approach also repeats the Source
table three times. While this works for a small number of repetitions, it quickly becomes cumbersome as the number of repetitions increases. Imagine if you needed to repeat the table 10 or 20 times—you’d have to keep manually writing Source
again and again, which isn’t practical.
Full M Code
To try this yourself, you can use the following M code:
let
Source = #table(
type table[ ProductKey = Int64.Type, Product = Text.Type, Sales = Int64.Type ],
{
{ 1, "Product A", 150 },
{ 2, "Product B", 200 }
}
),
RepeatedTable = Table.Repeat( Source, 3 ),
ManualApproach = Source & Source & Source
in
ManualApproach
Related functions
Other functions related to Table.Repeat are:
- Table.AlternateRows
- Table.Distinct
- Table.InsertRows
- Table.Range
- Table.RemoveFirstN
- Table.RemoveLastN
- Table.RemoveMatchingRows
- Table.RemoveRows
- Table.Skip
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy