Using Power Automate Expressions and Functions

Loading

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.

FunctionDescriptionExampleOutput
concat()Combines multiple text valuesconcat('Power ', 'Automate')Power Automate
substring()Extracts part of a stringsubstring('Automation', 0, 4)Auto
toUpper()Converts text to uppercasetoUpper('hello')HELLO
toLower()Converts text to lowercasetoLower('HELLO')hello
trim()Removes spaces from the beginning and endtrim(' Power ')Power

Numeric Functions (Math Operations)

These functions perform calculations and conversions on numbers.

FunctionDescriptionExampleOutput
add()Adds numbersadd(10, 5)15
sub()Subtracts numberssub(10, 5)5
mul()Multiplies numbersmul(3, 4)12
div()Divides numbersdiv(10, 2)5
mod()Returns remaindermod(10, 3)1

Date and Time Functions

These functions help in handling and formatting date/time values.

FunctionDescriptionExampleOutput
utcNow()Gets the current UTC timeutcNow()2025-03-05T12:00:00Z
addDays()Adds days to a dateaddDays(utcNow(), 5, 'yyyy-MM-dd')2025-03-10
addHours()Adds hours to a timeaddHours(utcNow(), 3)2025-03-05T15:00:00Z
formatDateTime()Formats a date/timeformatDateTime(utcNow(), 'yyyy-MM-dd')2025-03-05

Collection and Array Functions

These functions help process lists and arrays.

FunctionDescriptionExampleOutput
length()Returns the number of itemslength(['A', 'B', 'C'])3
contains()Checks if a value existscontains(['A', 'B', 'C'], 'B')true
first()Gets the first itemfirst(['Red', 'Blue', 'Green'])Red
last()Gets the last itemlast(['Red', 'Blue', 'Green'])Green
join()Combines array values into a stringjoin(['Apple', 'Banana'], ', ')Apple, Banana

Control and Logical Functions

These functions control conditions and flow logic.

FunctionDescriptionExampleOutput
if()Returns a value based on a conditionif(10 > 5, 'Yes', 'No')Yes
equals()Checks if values are equalequals(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 conditionnot(equals(5, 5))false

Using Expressions in Power Automate

To use expressions in Power Automate:

  1. Open Power Automate and create/edit a flow.
  2. In an action field, click on “Expression”.
  3. Enter the function (e.g., concat('Hello', ' World!')).
  4. 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

Leave a Reply

Your email address will not be published. Required fields are marked *