Text.Repeat in Power Query returns a text value repeated a given number of times, and you use it by adding a custom column or editing an existing step in the Power Query Editor with the formula Text.Repeat(text, count). It is a small function, but it is genuinely useful for padding codes, building fixed-width identifiers, creating separators, and testing string lengths. The function takes exactly two arguments: the text to repeat (a text value) and the number of times to repeat it (a whole number). If the count is zero, you get an empty string; if the count is negative, Power Query returns an error. Everything below assumes you already have a query open in the Power Query Editor, which you reach from Excel via Data > Get Data, or from Power BI via Transform data.

What You'll Need

  • A workbook or Power BI file with at least one table or query loaded into Power Query.
  • The Power Query Editor open (in Excel: Data > Get Data > Launch Power Query Editor; in Power BI Desktop: Home > Transform data). Menu labels can differ slightly by version, edition and region.
  • A text column you want to repeat, or a fixed piece of text you want to build from.
  • A whole-number column or a literal number for the repeat count. The count must be an integer; decimals cause an error unless you round them first.

Step-by-Step

  1. Load your data into Power Query. Select your table in Excel and choose Data > From Table/Range, or connect to your source in Power BI. Confirm the preview shows the columns you expect.
  2. Check the data types. Click the icon at the left of the column header for the text you plan to repeat and set it to Text. Do the same for the count column and set it to Whole Number. Text.Repeat fails if the first argument is a number or the second is text, so this step prevents most errors.
  3. Decide where the result should go. For a new output column, use Add Column > Custom Column. To change an existing column in place, right-click the column header and choose Replace Values or use Transform > Format, but a custom column is safer because it keeps the original data.
  4. Write the formula. In the Custom Column dialog, name the column (for example PaddedCode) and enter a formula such as Text.Repeat("0", 5 - Text.Length([Code])) & [Code] to left-pad a code to five characters. For a simple repeat of a fixed string, use Text.Repeat("-", 10). For a column-driven repeat, use Text.Repeat([Symbol], [Count]). The formula is case-sensitive: it must be Text.Repeat, not text.repeat.
  5. Confirm the dialog. Click OK. Power Query adds a new step to the Applied Steps list on the right and shows a preview column. If the preview shows Error in every row, the formula or a data type is wrong; if only some rows show errors, those rows have a bad count or a null text value.
  6. Handle nulls before repeating. If either argument can be null, wrap the call: Text.Repeat(Text.From([Symbol] ?? ""), [Count] ?? 0). The ?? operator supplies a fallback when the value is null. Without it, a null count produces an error.
  7. Round non-integer counts. If your count column contains decimals, wrap it in Number.RoundDown([Count]) or change the column type to Whole Number, which rounds automatically. Text.Repeat needs an integer.
  8. Rename and reorder. Double-click the new column header to rename it, then drag it where you want it. Renaming does not affect the formula.
  9. Apply the changes. In Excel, choose Home > Close & Load to send the result to a worksheet. In Power BI, choose Home > Close & Apply. The query refreshes with the new column each time the data reloads.

Common Mistakes

  • Wrong argument order. Text.Repeat expects the text first and the count second. Reversing them gives an error or an unexpected result.
  • Lowercase function name. M is case-sensitive. text.repeat is not recognised; use Text.Repeat.
  • Passing a number as text. If the first argument is a numeric column, wrap it in Text.From(). Text.Repeat does not convert numbers for you.
  • Negative or decimal counts. Negative counts return an error, and decimals are rejected. Clean the count column first.
  • Ignoring nulls. A single null in either argument breaks the whole row. Use ?? fallbacks or filter nulls out before the step.
  • Expecting it to pad automatically. Text.Repeat only repeats; it does not know your target length. You must calculate the count yourself, for example with 5 - Text.Length([Code]).
  • Editing the wrong step. If you insert a custom column in the middle of a query, later steps may fail because the column they reference has moved. Add the column at the end unless you have a reason not to.

Tips

  • Use Text.Repeat to build separators or fixed-width layouts, such as Text.Repeat("=", 20) for a divider row.
  • Combine it with Text.PadStart and Text.PadEnd when you only need padding; those functions are simpler than calculating a repeat count by hand.
  • Keep a small reference query with test formulas so you can check behaviour without touching production data.
  • Use the formula bar to review the generated step; it shows the exact M code and is easier to edit than the dialog for long expressions.
  • Name custom columns clearly so the Applied Steps list stays readable when you revisit the query later.

Troubleshooting

If every row shows an error, open the step in the formula bar and check three things in order: the function name is capitalised as Text.Repeat, the first argument is text, and the second is a whole number. If only some rows fail, filter the count column for nulls, negatives and decimals and fix them before the step. If the column type changed unexpectedly, set it explicitly with Transform > Data Type. If the query is slow, the repeat count may be very large; check for a runaway value such as a count of thousands. If the result looks wrong rather than erroring, confirm the argument order and that you are not repeating a column you meant to pad. When a step breaks after you insert a new column earlier in the query, delete the new step, add it at the end, and reapply.

Frequently Asked Questions

What does Text.Repeat do in Power Query?

It returns a text string repeated a specified number of times, for example Text.Repeat("ab", 3) returns ababab.

Can I repeat a column value rather than fixed text?

Yes. Pass the column reference as the first argument, such as Text.Repeat([Symbol], [Count]), after setting both columns to the correct data types.

Why does Text.Repeat return an error for zero or negative counts?

A count of zero returns an empty string, which is valid. Negative counts are invalid and produce an error, so clean the count column first.

Does Text.Repeat work with numbers?

Only if you convert them to text first with Text.From(). The first argument must be a text value.

How do I pad a code to a fixed length?

Calculate the difference between the target length and the current length, then repeat the pad character that many times and concatenate, or use Text.PadStart instead.

Is Text.Repeat available in both Excel and Power BI?

Yes. Both use the same Power Query engine, so the function behaves the same in each, though menu labels can differ slightly by version.