Power Automate provides a set of built-in expressions and functions that help users manipulate data, perform calculations, and control the flow of automation. These expressions are primarily used in Dynamic Content fields and written using Power Fx syntax.
Understanding Expressions in Power Automate
Expressions in Power Automate follow a function-based syntax similar to Excel and JavaScript. They are enclosed in @
notation or can be directly used inside dynamic fields.
Example:
@{concat('Hello ', 'World!')}
This concatenates two text strings and outputs:
“Hello World!”
Commonly Used Power Automate Functions
String Functions (Text Manipulation)
These functions help modify and manipulate text values.
Function | Description | Example | Output |
---|---|---|---|
concat() | Combines multiple text values | concat('Power ', 'Automate') | Power Automate |
substring() | Extracts part of a string | substring('Automation', 0, 4) | Auto |
toUpper() | Converts text to uppercase | toUpper('hello') | HELLO |
toLower() | Converts text to lowercase | toLower('HELLO') | hello |
trim() | Removes spaces from the beginning and end | trim(' Power ') | Power |
Numeric Functions (Math Operations)
These functions perform calculations and conversions on numbers.
Function | Description | Example | Output |
---|---|---|---|
add() | Adds numbers | add(10, 5) | 15 |
sub() | Subtracts numbers | sub(10, 5) | 5 |
mul() | Multiplies numbers | mul(3, 4) | 12 |
div() | Divides numbers | div(10, 2) | 5 |
mod() | Returns remainder | mod(10, 3) | 1 |
Date and Time Functions
These functions help in handling and formatting date/time values.
Function | Description | Example | Output |
---|---|---|---|
utcNow() | Gets the current UTC time | utcNow() | 2025-03-05T12:00:00Z |
addDays() | Adds days to a date | addDays(utcNow(), 5, 'yyyy-MM-dd') | 2025-03-10 |
addHours() | Adds hours to a time | addHours(utcNow(), 3) | 2025-03-05T15:00:00Z |
formatDateTime() | Formats a date/time | formatDateTime(utcNow(), 'yyyy-MM-dd') | 2025-03-05 |
Collection and Array Functions
These functions help process lists and arrays.
Function | Description | Example | Output |
---|---|---|---|
length() | Returns the number of items | length(['A', 'B', 'C']) | 3 |
contains() | Checks if a value exists | contains(['A', 'B', 'C'], 'B') | true |
first() | Gets the first item | first(['Red', 'Blue', 'Green']) | Red |
last() | Gets the last item | last(['Red', 'Blue', 'Green']) | Green |
join() | Combines array values into a string | join(['Apple', 'Banana'], ', ') | Apple, Banana |
Control and Logical Functions
These functions control conditions and flow logic.
Function | Description | Example | Output |
---|---|---|---|
if() | Returns a value based on a condition | if(10 > 5, 'Yes', 'No') | Yes |
equals() | Checks if values are equal | equals(10, 10) | true |
and() | Checks multiple conditions (AND) | and(equals(5, 5), equals(10, 10)) | true |
or() | Checks multiple conditions (OR) | or(equals(5, 5), equals(5, 10)) | true |
not() | Returns the opposite of a condition | not(equals(5, 5)) | false |
Using Expressions in Power Automate
To use expressions in Power Automate:
- Open Power Automate and create/edit a flow.
- In an action field, click on “Expression”.
- Enter the function (e.g.,
concat('Hello', ' World!')
). - Click OK and save the flow.
Real-World Use Cases
Use Case 1: Formatting a Date in Email
- Function:
formatDateTime(utcNow(), 'MMMM dd, yyyy')
- Output: March 05, 2025
Use Case 2: Extracting First Name from Full Name
- Function:
first(split('John Doe', ' '))
- Output: John
Use Case 3: Check if an Email Contains “Microsoft”
- Function:
contains('user@microsoft.com', 'microsoft')
- Output: true