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