Master String to Data Type Conversions in Power Automate
When working with Power Automate, data is often received as text (string) from various sources such as SharePoint, Excel, Forms, APIs, Dataverse, and JSON payloads. However, many actions require specific data types like Integer, Float, Boolean, Date, Array, or Object. Therefore, converting strings into appropriate data types is an essential skill for building efficient flows.
In this article, we'll explore how to convert string values into different data types using Power Automate expressions.
Why Convert Data Types?
Data type conversion helps:
- Prevent flow errors
- Improve data accuracy
- Support calculations
- Enable filtering and conditions
- Process API responses correctly
- Improve automation reliability
Prerequisites
Before starting:
- Power Automate Environment
- Basic understanding of Expressions
- Sample string values
Example Input:
"100"
"99.99"
"true"
"2025-06-17"
"[1,2,3]"
{"Name":"John","Age":30}
Convert String to Integer
Suppose the string value is:
"100"
Use the following expression:
int('100')
Output:
100
This converts the string into an Integer data type.
Convert String to Float
String Value:
"99.99"
Expression:
float('99.99')
Output:
99.99
Useful for currency and decimal calculations.
Convert String to Boolean
String Value:
"true"
Expression:
bool('true')
Output:
true
Another example:
bool('false')
Output:
false
Convert String to Date
String Value:
"2025-06-17"
Expression:
formatDateTime('2025-06-17','dd-MM-yyyy')
Output:
17-06-2025
You can use different date formats based on your business requirements.
Convert String to Array
String Value:
"[Apple,Orange,Mango]"
Expression:
json('["Apple","Orange","Mango"]')
Output:
["Apple","Orange","Mango"]
The string is converted into an Array object.
Convert String to JSON Object
String Value:
{"Name":"John","Age":30}
Expression:
json('{
"Name":"John",
"Age":30
}')
Output:
{"Name":"John","Age":30}
This converts the string into a usable JSON object.
Convert String to Number Using Compose
Example:
"500"
Expression:
int(outputs('Compose'))
Output:
500
This method is commonly used when values come dynamically from previous actions.
Real-Time Example
Suppose a Microsoft Form returns:
{"EmployeeID":"1001","Salary":"50000.50","IsActive":"true"}
Convert values:
- EmployeeID:
int(EmployeeID) - Salary:
float(Salary) - ActiveStatus:
bool(IsActive)
These conversions allow Power Automate to process the data correctly.
Common Conversion Functions
| Function | Purpose |
|---|---|
int() |
Convert String to Integer |
float() |
Convert String to Decimal |
bool() |
Convert String to Boolean |
string() |
Convert Value to String |
json() |
Convert String to JSON |
formatDateTime() |
Convert Date String |
concat() |
Combine Strings |
coalesce() |
Handle Null Values |
Benefits
- Better Data Processing: Ensures correct data formats.
- Accurate Calculations: Supports mathematical operations.
- Improved Flow Stability: Reduces runtime failures.
- Enhanced API Integration: Processes JSON responses effectively.
- Simplified Automation: Makes complex workflows easier to manage.
Best Practices
- Validate Input Values: Always check values before conversion.
- Use Compose Actions: Test expressions using Compose.
- Handle Null Values:
Example:
coalesce(triggerBody()?['Amount'],0) - Use Try-Catch Logic: Handle unexpected data formats gracefully.
- Test with Different Inputs: Verify results using multiple scenarios.
Common Use Cases
- SharePoint Data Processing: Convert text fields into numbers.
- Excel Calculations: Perform mathematical operations.
- API Integrations: Process JSON payloads.
- Dataverse Updates: Update numeric and Boolean fields.
- Approval Workflows: Convert and validate user input values.
Conclusion
Data type conversion is one of the most commonly used techniques in Power Automate. Whether you're working with SharePoint, Dataverse, Excel, APIs, or Forms, converting string values into Integer, Float, Boolean, Date, Array, or JSON formats ensures your flows run smoothly and efficiently.
By using built-in Power Automate expressions like int(), float(), bool(), and json(), you can create robust automations that handle data accurately and reliably.