4 Various Ways to Use Compose Action in Power Automate [With Examples]

In Power Automate, the Compose action is a handy tool for creating and manipulating data within your flows. When building an automated process, you often need to work with different pieces of information, whether combining values, formatting text, or preparing data for later steps. The Compose action helps you do just that by letting you define and store data.

In this tutorial, I will explain the Compose action in Power Automate and its versatility through various practical scenarios. You will learn how to use Compose for tasks like creating JSON formats, adding properties to arrays, converting arrays to strings, and converting strings to integers.

Compose Action in Power Automate

The Compose action in Power Automate is a versatile tool for creating, transforming, and storing data within flows. It enables users to input values or expressions that can be reused later in the flow, making information management easier.

The Compose action combines multiple pieces of data into a single output, such as merging text strings or modifying data formats, like adjusting dates or numbers. It acts as a temporary container that helps streamline data handling during the automation process.

Compose Action in Power Automate

The Power Automate Compose action accepts one parameter called Input. This parameter allows you to provide a single value or expression that you want to store or manipulate. The input can be a static value, a variable, or a result from a previous action in the flow. Once you’ve defined this input, you can use it in other actions within your Power Automate flow.

How to Use Compose Action to Create JSON Format in Power Automate

The Compose action in Power Automate is helpful when you must structure data into a specific format, like JSON, to send or use in other actions.

Imagine you have a SharePoint list containing customer orders and need to send the details of each order in JSON format to an external system.

For this example, I created a SharePoint list called Customer Order:

Use Compose Action to Create JSON Format

Now follow the below steps:

1. Create an automated cloud flow. Give the flow name and select the trigger When an item is created. Also, provide the Site Address and List Name.

Compose Action to Create JSON Format in Power Automate

2. Add a compose action and provide the below input value:

{
  "OrderID": @{triggerBody()?['OrderID']},
  "CustomerName": @{triggerBody()?['CustomerName']},
  "Product": @{triggerBody()?['Product']},
  "Quantity": @{triggerBody()?['Quantity']},
  "Price": @{triggerBody()?['Price']}
} 
power automate compose json

If you want, you can add send an email action to send this JSON format.

Now click on Save and run the Flow manually. Once the flow runs, add an item to the SharePoint list.

How to Use Compose Action to Create JSON Format in Power Automate

After the flow runs successfully, you can see the JSON in the compose output.

How to Use Compose Action to Create JSON Format using Power Automate

How to Add a Property to an Array using Compose Action in Power Automate

Let’s say you’re managing a list of employees in Power Automate and want to add a “Location” property to each employee record in the array. This can help organize your data without changing the original source.

Now follow the below steps:

1. Go to Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

Power Automate compose array

2. Add the Initialize variable action and Name the variable “EmployeeArray,” set the type to Array, and add the following array as the Value:

[
    {
        "FullName": "Taylor Smith",
        "Age": 28,
        "Department": "Marketing"
    },
    {
        "FullName": "Jamie Lee",
        "Age": 35,
        "Department": "Finance"
    }
]
power automate compose action array

3. Add the Apply to each action, using the EmployeeArray variable as the input to loop through each object in the array.

how to use compose in power automate

4. Inside the loop, add a Compose action. In the Input field, use the following expression to add a “Location” property to each employee object:

addProperty(item(), 'Location', 'New York')
Add a Property to an Array using Compose Action in Power Automate

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

How to Add a Property to an Array using Compose Action in Power Automate

How to Use Compose Action Convert Array to String using Power Automate

Suppose you have a SharePoint list called Project Tasks. Inside this list, there’s a column called Assigned To (Person), which allows multiple people to be assigned. When a new item is created, you want to send an email to the manager. However, if you directly include the assigned people’s display names, Power Automate will treat this as an array and apply a For Each loop, which is incorrect.

In this example, we’ll see how to convert an array to a string in Power Automate, allowing you to send all assigned people’s names in a single email.

1. Create an automated cloud flow. Give the flow name and select the trigger When an item is created. Also, provide the Site Address and List Name.

Compose Action Convert Array to String using Power Automate

2. Add a select action to pull out only the Assigned People name field from the array.

Power Automate compose array to string

3. Add a Compose action. In the Compose field, use the join function:

join(body('Select'), ', ')

This expression joins the names in the array, separated by a comma and space.

Use Compose Action Convert Array to String using Power Automate

4. Then, Add the Send an email action inside the true section and provide the below parameters:

  • To: Provide manager email.
  • Subject: Provide a subject line for a mail.
  • Body: Provide a detailed description of a mail.
what is compose in power automate

Now click on Save and run the Flow manually. Once the flow runs, add an item to the SharePoint list.

compose array to string in Power Automate

After the flow runs successfully, your manager gets an email.

How to Use Compose Action Convert Array to String using Power Automate

How to Use Compose Action to Convert String to Integer Using Power Automate

Now, I will show you how to use the compose action to convert a string to an integer using Power Automate.

1. Go to Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

power automate examples

2. Add the Initialize variable action and Name the variable “varString,” set the type to String, and add the Value as 24:

compose in power automate

3. Add a Compose action and use the Int function to convert the string to an integer:

int(variables('varString'))
data operations Compose Action in power automate

Now click on Save and run the Flow manually. The result will be displayed in the output of the Compose action.

How to Use Compose Action to Convert String to Integer Using Power Automate

Compose vs Variable Action in Power Automate

I will explain the difference between Power Automate compose and variable action.

Variable ActionCompose Action
Requires a specific data type (e.g., string, boolean, array). If data doesn’t match the type, it causes an error.It is Typeless, meaning it’s flexible with any data type (e.g., XML, JSON).
Works well in loops to increment or accumulate values, build arrays, or manage counters.It is limited within loops as it can’t be updated but can still hold static data or fixed calculations.
It Can be updated multiple times. You can set and reset values at different stages of the flow.Set only once; no update function. It holds the value as given.
Variables are grouped, making them easy to find and identify in Dynamic Content.It is not grouped and appears as an individual item in Dynamic Content, labeled by the name of the Compose action.
It requires initialization with a name, type, and initial value. Typically initialized at the top of the flow.It can be placed anywhere in the flow without prior setup.

In this article, I explained how to use the Compose action in Power Automate for various data-handling tasks, such as creating JSON, adding properties to arrays, converting arrays to strings, and converting strings to integers. I also covered how Compose differs from the Variable action.

Related Power Automate articles:

  • 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!

  • >

    Build a High-Performance Project Management Site in SharePoint Online

    User registration Power Apps canvas app

    DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

    Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

    Power Platform Tutorial FREE PDF Download

    FREE Power Platform Tutorial PDF

    Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…