1 Step to create the REPT function in Power Automate Microsoft Power Automate repeat

Today I was asked on the chat about how to create a REPT function in Power Automate. Excel has a REPT function to repeat the same text a specified number of times. Howe to do this in Power Automate.

The REPT Function

In Excel you can use REPT(“Text”, 3) and then you will get “TextTextText” as a result. Within Power Automate this is a bit harder, but we can do this ion one single action.

REPT Function in Excel

The Power Automate REPT() equivalent

First of all I’m going to add a trigger that takes two parameters. My text and the repeat count can then be supplied.

1 Step to create the REPT function in Power Automate Microsoft Power Automate image

Then we need just one Compose action that gives us the REPT fucntion

The REPT function to repeat texts in Power Automate

The expression used is:

replace(replace(formatNumber(0,Concat('C',triggerBody()['number'])),'$0.',''),'0',triggerBody()['text'])

Ok, that needs a bit of explaining.

formatNumber

I’m first having a look at the format number fucntion:

formatNumber(0,Concat('C',triggerBody()['number']))

The format number function is going to generate us smoothing like this:

$0.00000

For more information on the format strings please have a look at the Microsoft documentation for number formatting.

In our case if we set the number to 5 we will construct the number format C5 which stands for currency with 5 digits after the dot.

formatNumber(0,'C5')

Replace functions

Then we have two replace functions. First we are replacing the “$0.” with nothing. before we replace every 0 with the text that we want to repeat.

REPT Function in Power Autumate

Limitations

The formatNumber has C99 as a maximum limitation. So this method will only work for up to 100 repeats. For any larger numbers we might have to do some looping around in our flows.

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as a Principal Architect at HybrIT Services Ltd. You can contact me using contact@sharepains.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue Reading

%d