Power Automate Compose + 15 Examples

In this Power Automate tutorial, we will discuss Power Automate compose action. And also we will discuss the below points:

  • Power automate compose
  • Power automate compose vs variable
  • Power automate compose JSON
  • Power automate compose array
  • Power automate compose expression
  • Power automate compose array to string
  • Power automate compose append string
  • Power automate compose addition
  • Power automate compose concat
  • Power automate compose first item in array
  • Power automate compose formatdatetime
  • Power automate compose length
  • Power automate compose today’s date
  • Power automate compose string to integer
  • Power automate compose union

Power Automate compose action

The compose is a data operation action in Power Automate or Microsoft Flow that will create an arbitrary object from the inputs.

Power Automate compose vs variable

Here we will discuss the difference between the compose and variable in Power Automate.

VariableCompose
Variables hold different types of data types like string, boolean array, etc, to validate what we give in terms of our data. If the data doesn’t match the data types it will give an error.Compose action is typeless, which means it is very flexible, we can provide any type of data(we can give XML, JSON, etc) as an input.
Variables can be set many times, which means we can set it, reset it at any point of our flow, as per our requirement.Compose only set once, which means compose doesn’t have the update function
It can be grouped together under the variable heading, which means when we access the variable from the dynamic content. It was very clearly visible in the dynamic content because we can see the name of a variable, and also make it easy to identify what the variable is in dynamic content and what variable I want to use.Compose are not grouped, which means we give some data as input and it will return some data as output. So in dynamic content, we can only identify the output as the name of the compose action itself.
Variables need to be initialized, while initializing we need to give name, type, and initial value. When we initialize a variable, the initialize variable action can’t declare within the scope, and it is generally declared in the top level of the flow.Compose can be created anywhere in the flow, it can be created inside the scope or at any point throughout the flow
power automate compose vs variable

Read How to call a flow from another flow in Power Automate

Power Automate compose JSON

Here we will see an example of Power Automate compose JSON.

Now we will create a flow that will retrieve data from the SharePoint list and build a JSON.

Let’s see an example of Power Automate compose JSON.

I have a SharePoint list called Leaves Request, so from this list, we will retrieve items and build a JSON using compose action.

 JSON in power automate compose
JSON in power automate compose

In Power Automate, select the Manually triggered flow, then click on the Next step.

power automate compose JSON
power automate compose JSON

Now we will retrieve items from the SharePoint list, so click on the Next step and select Get items action, then provide the site address, list name.

Microsoft flow compose JSON
Microsoft flow compose JSON

Next, initialize variable as an array, so click on the Next step and select Initialize variable action, set the name as itemsArray, type set to Array, and value is empty.

MS flow compose JSON
MS flow compose JSON

Now add an Apply to each action, the provide the value from dynamic content. Then add an action and select compose action, then in input provide the value like below.

 compose JSON in MS flow
compose JSON in MS flow

Next, click on the Next step and select Append to array variable action, then select the variable name and in value select the output from the dynamic content.

compose JSON in Microsoft flow
compose JSON in Microsoft flow

After the Apply to each action, click on the Next step and select Compose action. Then in input write the below formula.

 JSON in power automate compose action
JSON in power automate compose action

Now click on Save and run the flow, you can see the JSON in the compose output.

 compose  JSON in power automate
compose JSON in power automate

This is an example of Power Automate compose JSON.

Read Power Automate Set Variable

Power Automate compose array

Here we will see how to add a property to an array using Compose action in Power Automate.

In Power Automate, select the Manually triggered flow, then click on the Next step.

power automate compose array
power automate compose array

Now we will initialize the array variable, so click on the Next step and select initialize variable action. Then provide the variable name, type as an array, and in value write the below array:

[
{
"FullName": "Christen Ronald",
"Age":30,
"Address":"Arizona"
},
{
"FullName": "Alex Ronald",
"Age":32,
"Address":"Alaska"
}
]
power automate compose array
power automate compose array

In the Next step, select Apply to each action and select the variable as an output from the dynamic content.

Then we will add a property to each object in an array, so click on add action and select Compose action. Then in input add the below expression:

addProperty(item(),'Department','HR')
Microsoft flow compose array
Microsoft flow compose array

Now click on Save and run the flow, you can see the property added to each object in an array.

Microsoft flow compose array of objects
Microsoft flow compose an array of objects

This is an example of Power Automate compose array.

Read Power Automate wait timer – How to use

Power automate compose expression

Here we will see how to use the expression in Compose action in Power automate.

In compose we will write an expression, which will replace the string ‘Automate’ with ‘Apps’.

In Power Automate, select the Manually triggered flow, then click on the Next step.

power automate compose expression
power automate compose expression

Select the Initialize variable action, then provide the variable name, type as a string, and in value like below.

power automate compose expression
power automate compose the expression

Now add a compose action to replace automate with apps, so click on the Next step and select Compose action. Then in Input write the below expression.

replace(variables('varString'),'Automate','Apps')
Microsoft Flow compose expression
Microsoft Flow compose expression

Now, click on Save and run the Flow manually, you can see the output of the compose action.

MS Flow compose expression
MS Flow compose expression

This is an example of Power Automate compose expression.

Read Power Automate update SharePoint list increment integer field

Power Automate compose array to string

Here we will see how to convert array to string using Power Automate.

We will create a flow that will convert the below array to string using Power Automate.

[
  {
    "DisplayName": "Bob Jones",
    "Email": "[email protected]",
    "JobTitle": "Singer"
  },
  {
    "DisplayName": "Jane Doe",
    "Email": "j[email protected]",
    "JobTitle": "Lighthouse Painter"
  }
]

After converting the array we will get the below string:

Jane Doe – [email protected] – Lighthouse Painter
Bob Jones – [email protected] – Singer

Let’s see how to create a flow to convert the array to string using Power Automate.

In Power Automate, select the Manually triggered Flow, then click on the Next step.

convert array to string in Power Automate compose
convert array to string in Power Automate compose

Select Initialize variable action, then provide the variable name, type as Array, and in value add the above array.

power automate compose array to string
power automate compose array to string

To store the output string, click on the Next step and select Initialize variable action, then provide the variable name, and type as a string.

Microsoft Flow compose array to string
Microsoft Flow compose array to string

Now to convert the array to string, click on the Next step, add Apply to each action. and select vararray from the dynamic content as an output.

Then click on Add an action and select Compose action, then in Inputs write the below expression.

concat(item()?['DisplayName'],' - ',item()?['Email'],' - ',item()?['JobTitle'])
MS Flow compose array to string
MS Flow compose array to string

Then click on Add an action, and select Compose action, then in inputs add the output from the dynamic content, then go to next step and select FinalString from the dynamic content.

compose array to string in MS Flow
compose array to string in MS Flow

Now we will set the variable, so click on the Next step and select Set variable action, then provide the variable name and in value, select the outputs from the dynamic content.

compose array to string in Microsoft Flow
compose array to string in Microsoft Flow

Now click on the Next step, and select Compose action, then in Inputs select the FinalString from the dynamic content.

compose array to string using MS Flow
compose array to string using MS Flow

Now click on Save and run the flow manually and you can see the output in the compose action.

compose array to string using Microsoft Flow
compose array to string using Microsoft Flow

This is an example of Power Automate compose array to string.

Read How to move emails to folder after 30 days using Power Automate

Power Automate compose append string

Here we will see an example of append string in Power Automate compose action.

So here we want multiple user Emails from the SharePoint person field to send a Notification, so we need to Append to the string variable.

For this example I will use the Project management list, there is a column Assigned to which is a person field.

power automate compose append string
power automate compose append string

In Power Automate, select the trigger ‘When an item is created’- SharePoint list. Then provide the site address and list name.

Microsoft Flow compose append string
Microsoft Flow compose append string

Next, Initialize a variable as String, so click on the Next step and select Initialize variable action, then provide the variable name and type as a string.

MS Flow compose append string
MS Flow compose append string

Now we will Append each email to the string variable, so click on the Next step and select Append to a string variable, then select the variable name and in value select the person field, that will automatically add Apply to each action.

compose append string using MS Flow
compose append string using MS Flow

Next, add a compose action, then in input select the varuserEmail from the dynamic content.

compose append string using Microsoft Flow
compose append string using Microsoft Flow

Now click on Save and to run the flow create an item in the SharePoint list, and you can see multiple emails are separated with ‘;’

compose append string using Flow
compose append string using Flow

This is an example of power automate compose append array.

Read Power Automate list rows present in a table filter query

Power Automate compose addition

Here we will see how to add two numbers or integers in the compose action.

In Power Automate, select the Manually triggered flow, then click on the Next step.

power automate compose addition
power automate compose addition

Now we will initialize two integer variables, so click on the Next step and Initialize variable action then provide the variable name, type as integer and provide the value.

power automate compose addition
power automate compose addition

Next we will add the two integer variable, so click on the Next step and select compose action, then in input add the below expression:

add(variables('num 1'),variables('num2'))
MS Flow compose addition
MS Flow compose addition

Now click on Save and run the flow manually and you can the addition of two number.

Microsoft Flow compose addition
Microsoft Flow compose addition

This is an example of Power Automate compose addition.

Check out, Power Automate Get Events into Excel

Power Automate compose concat

Here we will see how to use concat function in Power Automate compose action.

In Power Automate, select the Manually triggered flow, then click on the Next step.

power automate compose concat
power automate compose concat

Now we will assign a string i.e. Power, to a variable, so select Initialize variable action, then provide the variable name, type as String, and in value provide Power Automate.

Microsoft flow compose concat
Microsoft flow compose concat

In this step we will concat the above string with another string i.e. Automate, so click on the Next step and select compose action. Then in input provide the below expression.

concat(variables('varString'),'Automate')
MS flow compose concat
MS flow compose concat

Now click on Save and run the Flow manually, and you can see both the string concatenated.

 compose concat in MS flow
compose concat in MS flow

This is an example of Power Automate compose concat.

Read Microsoft flow send email based on create date

Power Automate compose first item in array

Here we will see how to get the first item value in array using Power Automate.

So here we will use the below array and we will retrive the DisplayName i.e. Boby jones from an array.

[
  {
    "DisplayName": "Bob Jones",
    "Email": "[email protected]",
    "JobTitle": "Singer"
  },
  {
    "DisplayName": "Jane Doe",
    "Email": "j[email protected]",
    "JobTitle": "Lighthouse Painter"
  }
]

In Power Automate, select the Manually triggered Flow, then click on the Next step.

power automate compose first item in array
power automate compose first item in array

Select Initialize variable action, then provide the variable name, type as array, and in value provide the above array.

power automate compose first item in array
power automate compose first item in array

Now we will get the first item value, so click on the Next step and select compose action. Then in input provide the expression:

variables('varArray')?[0]?['DisplayName']
Microsoft flow compose first item in array
Microsoft flow compose first item in array

Now click on Save and run the Flow Manually, you can see the result in the compose output.

MS flow compose first item in array
MS flow compose first item in array

This is an example of Power Automate compose first item in array.

Read Power Automate or Microsoft Flow check day of week

Power Automate compose formatdatetime

Here we will see how to use formatdatetime function in Compose action using Power Automate.

In Power Automate select the Manually triggered flow, then click on the Next step.

format date 2
power automate compose formatdatetime

In this step, we will initialize variable as string, so select Initialize variable action, then provide the variable name, type as string and in value provide a sample date.

power automate compose formatdatetime
power automate compose formatdatetime

Now we will format the date with ‘yyyy-MM-dd’, so click on the Next step and select compose action. Then in input add the below expression:

formatDateTime(variables('Date'),'yyyy-MM-dd')
Microsoft Flow compose formatdatetime
Microsoft Flow compose formatdatetime

Now click on Save and run the Flow manually, you can see the result in the compose output.

MS Flow compose formatdatetime
MS Flow compose formatdatetime

This is an example of Power Automate compose formatdatetime.

Read Power Automate Desktop Flow – How to start

Power Automate compose length

Here we will see how to use length function in Compose action in Power Automate.

In Power Automate, select the Manually triggered flow, then click on the next step.

power automate compose length
power automate compose length

Then select the Initialize variable, provide the variable name, type as string and in value provide the sample string.

power automate compose length
power automate compose length

Next, add a Compose action, then in Input provide the below expression, that will measure the length of the above string.

length(variables('varString'))
Microsoft Flow compose length
Microsoft Flow compose length

Now click on Save and run the flow Manually, and you can see the length of the string.

MS Flow compose length
MS Flow compose length

This is an example of Power Automate compose length.

Read Power Automate SharePoint Get Items Filter Query

Power Automate compose today’s date

Here we will see how to get today’s date in Compose action in Power Automate.

In Power Automate, select the Manually triggered flow, then click on the Next step.

power automate compose today's date
power automate compose today’s date

Now we will get the today’s date, so select Compose action, then in Input provide the below expression:

formatDateTime(utcNow(),'yyyy-MM-dd')
power automate compose today's date
power automate compose today’s date

Now click on Save and run the flow manually, you can see the date in the compose action.

Microsoft Flow compose today's date
Microsoft Flow compose today’s date

This is an example of Power Automate compose today’s date.

Read Power Automate send email to SharePoint group

Power Automate compose string to integer

Here we will see how to convert string to integer Power Automate Compose action.

In Power Automate select the Manually triggered Flow, then click on the Next step.

string to integer in power automate compose
string to integer in power automate compose

Now select initialize a variable action, then provide the variable name, type as string and in value provide like below.

power automate compose string to integer
power automate compose string to integer

Next, add a Compose action, then in Input write the below expression to convert the above string into an integer.

int(variables('Text'))
Microsoft Flow compose string to integer
Microsoft Flow compose string to integer

Now click on Save and run the Flow manually, you can see the result in the output of the Compose action.

MS Flow compose string to integer
MS Flow compose string to integer

This is an example of Power Automate compose string to integer

Read Power Automate remove characters from a string

Power Automate compose union

Here we will see how to use union function in Power Automate Compose action.

In this example, we will take two arrays, and we will find the union of two arrays.

In Power Automate select the Manually triggered flow, then click on the Next step.

power automate compose union
power automate compose union

Select the Initialize variable action, then provide the variable name, type as Array, and provide the value like below:

power automate compose union
power automate compose union

Next, initialize an array variable, so click on the Next step and select Initialize variable action. Then provide the variable name, type as an array, and in value add the below array.

Microsoft Flow compose union
Microsoft Flow compose union

Now we will find the union between two array, so click on the Next step and select Compose action. Then in Input write the below expression:

union(variables('varArray1'),variables('varArray2'))
MS Flow compose union
MS Flow compose union

Now click on Save and run the Flow Manually, you can see the union of two arrays in the output of the compose action.

 union in MS Flow  compose
union in MS Flow compose

This is an example of the Power Automate compose union.

Related Power Automate tutorials:

In this Power Automate tutorial, we learned about Power Automate Compose action. And also we will discuss the below points:

  • Power automate compose
  • Power automate compose vs variable
  • Power automate compose JSON
  • Power automate compose array
  • Power automate compose expression
  • Power automate compose array to string
  • Power automate compose append string
  • Power automate compose addition
  • Power automate compose concat
  • Power automate compose first item in array
  • Power automate compose formatdatetime
  • Power automate compose length
  • Power automate compose today’s date
  • Power automate compose string to integer
  • Power automate compose union
  • Great post! How can I use the output of a “Compose” action (i.e. an array of names) to populate fields in a “Create Item” action? Thank you!

  • Thank you!!! Finally, a really helpful and detailed post with information I’ve not been able to find in the documentation. Your table of differences between variables and compose cleared up something for me that I’ve been struggling with for _years_. Invaluable! This information should be added to Microsoft’s official documentation!

  • >