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

The Text.Repeat function creates a new string by repeating a given text value a specified number of times. It’s useful for tasks like creating separator lines or repeating patterns. The function also handles null values gracefully, returning null if the input text is null.

Examples

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

Creating a Separator Line

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 expression, Power Query is instructed to create a string consisting of ten asterisks, providing you with your desired separator line.

Repeating a String Multiple Times

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.

Handling Null Values

One important 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.

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

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