Table.Repeat

Updated on

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:

Table.Repeat base table to start in Power Query M

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:

Table.Repeat duplicates table three times in Power Query M

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

Other functions related to Table.Repeat are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/table-repeat

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy