November 6, 2024

Building strings is one of the most common actions in any tool or framework, and Power Automate is not the exception. The Concat function helps us build from different pieces of data a string of data. I’ve written many articles that use this function for tasks like building messages to display to the user, combining information to generate JSON files, and more. So let’s explore a bit further.

Usage of the concat function

It follows a simple pattern where you provide one or more values, and they are combined into a string. Notice that I say “values” and not strings. 

Let’s start with a simple example:

concat('Manuel', ' T ', 'Gomes')

will return 

Manuel T Gomes

What about other types? Let’s use a variable “Test” with a boolean type:

concat('The result is: ', variables('TEST'))

will return 

The result is: False
Although you can see everywhere that the concat function is used to combine strings, you can use other datatypes freely without the need to “convert” the information.

Integer and Floats

Let’s try a few more. Same as above but for “Integer” values.

TEST variable is equal to 12

concat('The result is: ', variables('TEST'))

will return 

The result is: 12

How about “Float” values?

TEST variable is equal to 12.5

concat('The result is: ', variables('TEST'))

will return 

The result is: 12.5

Arrays

Now a tricky one. An array. We’ll use the same variable, and we’ll build the array using the “createArray function.”

createArray('Manuel','Teixeira','Gomes')

With this, the variable will be initialized with an array that we can use to test.

concat('The result is: ', variables('TEST'))

will return

The result is: ["Manuel","Teixeira","Gomes"]

It’s not the nicest way to display a set of values. If you want to combine the values of an array, I would recommend using the “join function.” You only need to pass the array and the separator. For example:

join(variables('TEST'),' ')

will return 

Manuel Teixeira Gomes

Much nicer.

Limitations

Microsoft provides some warnings regarding “base64”. Although the encoding and decoding are automatic, the concat function may return some incorrect values. Be careful in this case, or avoid it as much you can. You’ll rarely need to do a concatenation in this case, but if you do be sure to test it to get the correct results and deal with errors.

Also, there’s no documented limit for concatenations but keep it as low as possible. Having huge concatenations will make your life a lot harder debugging when something goes wrong.

Recommendations:

Here are some things to keep in mind.

Spaces

Concatenations will aggregate exactly what you provide to the function. So if you want spaces, for example, you need to add them yourself. It’s quite a common mistake so consider this.

Arrays

Don’t use the concat function on arrays. You can, but the result is rarely what you want. As mentioned before, use the “join function” to get nicer results.

Data types other than strings

As you saw before, the conventions are automatic, but you may get less than optimal results. For example, for a Boolean variable, you’ll get “False.” Rarely, we won’t show it that way—either “Yes/No” or in lowercase, for example. Automatic conversions are great but can be a problem. Another example is the Float data type. You may want to display to the user “3.14,” for example, but if you don’t do any conversion, you’ll get “3.141592653589,” which is not quite as user-friendly as the first one.

The idea is always to control what you’ll get, so be careful with other data types than stings where you don’t have 100% control over what you’ll get in the end.

Break it down

I would not go over 20 parameters in a concat function. 20 is not a defined limitation, but further than that, you’ll have a hard time debugging it. If necessary, build several smaller concatenations and combine them in the end. This will give you a view in each “section” and see if everything is as expected.

Don’t nest

You may be tempted to nest concat functions, because it will provide you with only one function that takes care of the full string. But as always, you’ll have a hard time debugging it. Break it down into smaller chunks that you can digest and analyze if something goes wrong.

I always prefer to add more actions with smaller parts than having only one huge formula. Combine them with a “scope action,” making things simpler and more organized.

Localization

Please note that formulas may have localization-based differences. For example, you should write “concat” with “, separating each of the arguments, but if your regional settings are set to Portugal, you should use “;” instead.

Sources:

Microsoft’s concat Function Reference

Back to the Power Automate Function Reference.

Photo by Jeffrey Brandjes on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

2 thoughts on “Power Automate: concat Function

  1. Thanks for the information. I am struggling with a scenario where I’m checking a condition where if the user’s email is an email in the array emails it removes the users email. If the users email is not in the array I am then joining the array of emails with ‘;’ to then use them as a list of emails to to send a message to. I’ve tried concat(join(body(‘Filter_Array_Emails)?[‘Email’], ‘;’), ‘;’, outputs(‘user_email’)?[‘body/mail’]) but continue getting error for invalid code structure. I’ve looked it over several times and I’m not seeing an issue. Is it possible to concat the output of join with additional text?

    1. Hi Kevin,
      I think you’re missing the quote at the end of the “Filter_Array_Emails”. It should be body(‘Filter_Array_Emails’)?[‘Email’].
      Can you please test and let me know if it solves your problem?

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon