Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query List.Repeat Function: Step-by-Step

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The List.Repeat function in Power Query repeats a list a specified number of times, producing a new list that contains the original elements repeated consecutively. For example, repeating {1,2} three times gives {1,2,1,2,1,2}. This is useful for generating test data, creating date sequences, or duplicating rows in a table. You can use it in the Power Query Editor (available in Excel and Power BI) by adding a custom column or writing an M expression. No prior coding experience is needed, but familiarity with the Power Query interface helps.

What You'll Need

  • A dataset loaded into Power Query Editor (Excel: Data > Get Data > From Table/Range; Power BI: Home > Transform Data).
  • A basic understanding of M language syntax (e.g., how to write = List.Repeat(...)).
  • Access to the "Add Column" tab in Power Query Editor.

Step-by-Step

  1. Open Power Query Editor. In Excel, select your data range and go to Data > From Table/Range (or From Other Sources if importing). In Power BI, click Transform Data from the Home tab.
  2. Add a custom column. Go to the "Add Column" tab and click "Custom Column." This opens a dialog where you write M expressions.
  3. Enter the List.Repeat expression. In the custom column formula box, type something like: = List.Repeat({1,2}, 3) This creates a column where each row contains the list {1,2,1,2,1,2}. You can replace {1,2} with any list (e.g., {1..5} for numbers 1 to 5) and 3 with any non-negative number.
  4. Use a column value as the list. If you want to repeat a list that is stored in a column (say a column named "ListColumn"), reference it directly: = List.Repeat([ListColumn], 2). This repeats whatever list is in each row's cell.
  5. Use a column value as the count. To repeat a fixed list a number of times that varies per row, reference a count column: = List.Repeat({1,2}, [CountColumn]). The count must be a non-negative whole number; if it's not, you'll get an error.
  6. Expand the list into rows. After creating the custom column, you'll see a list in each row. To turn these into separate rows, click the expand icon (double arrow) in the column header and choose "Expand to New Rows." This creates one row per element in each list.
  7. Combine with other functions. For example, to create a sequence of dates repeated multiple times, use = List.Repeat(List.Dates(#date(2025,1,1), 3, #duration(1,0,0,0)), 2). This gives a list of three dates repeated twice.
  8. Rename and change data type. After expanding, rename the new column as needed and set the data type (e.g., Whole Number, Date) using the column header icons.

Common Mistakes

  • Using a negative or non-integer count. List.Repeat requires a non-negative whole number. If you use -1 or 2.5, you'll get an error. Ensure your count column contains integers.
  • Forgetting the curly braces. Lists in M are written with curly braces, not parentheses. List.Repeat((1,2), 3) is invalid.
  • Confusing List.Repeat with List.Combine. List.Repeat duplicates the same list; List.Combine merges different lists. They are not interchangeable.
  • Not expanding the list. If you don't click the expand icon, you'll see "List" in the cells, not the actual values. The list is there, but you need to expand it to use the values in rows.
  • Using a column reference incorrectly. When referencing a column, use square brackets like [ColumnName], not quotes. Quotes are for text strings.

Tips

  • Test with a small example first. Before applying to a large dataset, try = List.Repeat({1,2}, 3) in a custom column to see the output.
  • Use List.Repeat for test data. Generate sample data by repeating a list of values. For example, = List.Repeat({"A","B","C"}, 10) creates 30 rows when expanded.
  • Combine with Table.FromList. If you need a table, you can wrap the result: = Table.FromList(List.Repeat({1,2}, 3), Splitter.SplitByNothing(), {"Value"}).
  • Remember that the result is a list, not a table. You often need to expand or convert it to a table before using it in a data model.
  • Use the formula bar. In Power Query, you can also write custom M code in the formula bar for a selected step, but the Custom Column dialog is easier for beginners.

Troubleshooting

Error: "Expression.Error: The value isn't a valid integer." This means your count is not a whole number. Check the count column for decimals or nulls. Use Number.Round to round, or filter out nulls before applying.

Error: "List.Repeat cannot be applied to a null value." If your list is null (e.g., the column has blanks), wrap it in List.Repeat(if [ListColumn] = null then {} else [ListColumn], 2).

You see "List" in the cells but no expand icon. The expand icon appears only when the column contains lists. If you see "List" but no icon, click on the column header and look for the expand button in the preview pane. If it's missing, the column might not be recognized as a list type—check the data type.

The output is a single row with a long list. That's correct—List.Repeat returns a list. To get rows, expand it. If you need a single column table, use Table.FromList.

Count is too large, causing memory issues. Repeating a list millions of times can slow down Power Query. Consider using List.Transform or generating data differently if you need huge outputs.

Frequently Asked Questions

Can I repeat a list of dates?

Yes, you can repeat any list, including dates. Use List.Repeat(List.Dates(#date(2025,1,1), 5, #duration(1,0,0,0)), 2) to get a list of 5 dates repeated twice.

How do I repeat each element individually instead of the whole list?

Use List.Transform and List.Repeat together. For example, List.Transform({1,2}, each List.Repeat({_}, 3)) gives . Then you can combine with List.Combine .

What if I want to repeat rows in a table?

You can use Table.TransformColumns to add a list column, then expand. Or use Table.Combine with List.Repeat on the table itself: Table.Combine(List.Repeat({table}, 3)).

Is List.Repeat available in all versions of Power Query?

Yes, List.Repeat is part of the standard M library and is available in Power Query in Excel 2016 and later, Power BI, and other tools that use Power Query.

Can I use a column value as the count if it's text?

No, the count must be a number. If your column is text, convert it with Number.From([CountColumn]) inside the expression.

How do I repeat a list a dynamic number of times based on a parameter?

You can use a parameter in your query. For example, create a parameter named RepeatCount and use List.Repeat({1,2}, RepeatCount). Parameters can be set in the query editor.