Text.Repeat

Updated on

Text.Repeat is a Power Query M function that repeats a text value a specified number of times. The function returns the repeated text value.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Text.Repeat(
   text as nullable text,
   count as number,
) as nullable text

Description

Returns a text value composed of the input text text repeated count times. The function takes two arguments: the text that you want to repeat, and the count that specifies the number of times the text should be repeated. The term ‘nullable’ signifies that the function can handle null values as well, returning null if the input text or count is null.

Examples

To help you better comprehend the application of the Text.Repeat function, let’s consider some practical examples.

Suppose you want to create a separator line using asterisks and you want it to span 10 characters across. The Text.Repeat function makes this task very easy.

Text.Repeat( "*", 10 ) // Output: "**********"

With this simple command, Power Query is instructed to create a string consisting of ten asterisks, providing you with your desired separator line.

Let’s take it a step further. Suppose you’ve developed a fondness for M&Ms and you want to express your obsession by repeating “M&Ms” five times. Here’s how Text.Repeat can accommodate your whim:

Text.Repeat( "M&Ms", 5 ) // Output: "M&MsM&MsM&MsM&MsM&Ms"
Text.Repeat function to repeat a string

This results in a single string with the term “M&Ms” concatenated five times.

One notable aspect of Text.Repeat is its compatibility with null values. When it receives a null value as an input, it behaves gracefully:

Text.Repeat( null, 5 ) // Output: null

In this scenario, regardless of the repetition count, the function returns a null value.

To conclude, Text.Repeat in Power Query M language offers a simple way to repeat text values.

Learn more about Text.Repeat in the following articles:

Other functions related to Text.Repeat are:

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