Compose in Power Automate
Compose in Power Automate
The Compose action in Power Automate is a simple yet powerful tool that allows you to store and manipulate data during a flow run. Whether you’re combining strings, preparing outputs, or storing JSON for further use, Compose offers a clean and efficient way to manage data.
In this guide, youβll learn how to use Compose in Power Automate effectively β with real-world examples, best practices, and expert insights to help you build better flows.
π Table of Contents
- What Is the Compose Action in Power Automate?
- Why Use Compose in Power Automate?
- Key Features of the Compose Action
- Real-World Use Cases for Compose
- Compose vs Variables
- Using Expressions with Compose
- Best Practices
- Common Pitfalls
- Summary
π§© What Is the Compose Action in Power Automate?
The Compose action is used to output a value without storing it in memory like a variable. It is typically used for:
- Testing and debugging expressions
- Formatting or transforming data
- Temporarily storing calculated values
- Reusing outputs multiple times in a flow
It doesn’t βdoβ anything β it just holds a value for use elsewhere in your flow.
π‘ Why Use Compose in Power Automate?
You should use Compose in Power Automate when:
- You want to simplify a complex expression
- You need to reuse a calculated result multiple times
- You want to visualize or debug dynamic values
- You need to structure JSON for use in HTTP or custom connectors
- Youβre chaining transformations like
concat()
,formatDateTime()
, orjoin()
β¨ Key Features of the Compose Action
Feature | Description |
---|---|
Stateless | Stores output for use in the same run, no memory consumption |
Lightweight | Faster than using variables for static or single-use values |
Dynamic | Supports full Power Automate expression language |
Debug-friendly | Easily view output during flow run to troubleshoot expressions |
πΌ Real-World Use Cases for Compose in Power Automate
Here are practical scenarios where Compose is ideal:
πΉ Use Case 1: Format a Date
formatDateTime(utcNow(), 'MMMM dd, yyyy')
Use Compose to format the current date, and then reference it in email or Teams message.
πΉ Use Case 2: Combine Strings
concat('Customer Name: ', triggerOutputs()?['body/CustomerName'])
This output can be reused in a condition or message action.
πΉ Use Case 3: Clean Up Data Before Output
Use Compose to trim whitespace or convert values:
trim(triggerOutputs()?['body/Comment'])
πΉ Use Case 4: Prepare JSON for HTTP Request
{
"id": "@{outputs('Get_item')?['body/ID']}",
"name": "@{outputs('Get_item')?['body/Title']}"
}
Build structured JSON in a Compose step and send it via HTTP.
π Compose vs Initialize Variable
Feature | Compose | Variable |
---|---|---|
Stateless | β | β |
Used in Loops | β | β |
Memory Efficient | β | β |
Multiple Reuse | β | β |
Supports Expressions | β | β |
Best Practice: Use Compose when you donβt need to change the value after setting it.
π§ Using Expressions with Compose in Power Automate
You can write Power Automate expressions directly in the Compose action using the expression editor.
Popular examples:
- String manipulation:
toUpper(triggerOutputs()?['body/Name'])
- Math calculation:
add(10, 5)
- Check for nulls:
coalesce(triggerOutputs()?['body/Email'], 'No email provided')
- Create arrays:
createArray('Apples', 'Bananas', 'Oranges')
β Best Practices for Using Compose in Power Automate
- β Name your Compose actions clearly (e.g., βFormatDateβ or βFullNameβ)
- β Reuse Compose outputs instead of retyping expressions
- β Keep Compose actions grouped near their usage
- β Use Compose for debugging dynamic content before you finalize the flow
- β Store JSON responses in Compose for easier mapping later
β οΈ Common Pitfalls to Avoid
Pitfall | Solution |
---|---|
Using Compose inside loops for accumulation | Use variables instead |
Accessing undefined values | Wrap in coalesce() or use conditionals |
Repeating expressions | Use Compose once and reuse the output |
Misusing Compose for value changes | Compose is immutable β use variables if you need updates |
π Summary: Mastering Compose in Power Automate
The Compose action in Power Automate is a low-overhead way to store and reuse dynamic values, test expressions, and prepare outputs. It plays a crucial role in building scalable and maintainable flows.
Use Compose to:
- Format and transform data
- Store calculated outputs
- Simplify complex expressions
- Structure JSON or arrays