Expressions In Power Automate

Loading

Expressions are the set of functions that can be used to perform specific actions within a flow

  1. Expressions can be used in any flow action
  2. Expressions can be used in any flow condition
  3. Expressions can be used in flow trigger condition. useful to conditionally trigger flows and thereby save flow runs

Examples :-

  • Manipulate strings
  • Working with dates
  • Converting data types
  • Perform logical functions
  • Perform Mathematical Calculations
  • Perform complex conditional statements etc.

Sample expression :-

replace(text, oldText, newText )

sample data :-

replace(‘Expressions are difficult’, ‘difficult’, ‘fun’)

replace=function

Expressions are difficult=parameter 1

difficult=parameter 2

fun=parameter 3

Out put :- Expressions are fun

Expression Editor :-

Create an instant flow by choosing the trigger option “Manually trigger a flow”

Add a “compose” Data operation to the flow where we can test and see the result of our expressions.

Classic Editor :-

By default the Expression Editor will be in Classic mode.

1.Concat(‘Power’,’ ‘,’Automate’) : This expression will be used to concatenate or combine any number of Strings

Save the flow and Test it Manually.

The Result will be shown below where the strings “power” and “Automate” are combined as a single string.

Just use the eclipse of the compose and select the ‘Add a note’ to display the expression in compose for a clear understanding.

The expression can be seen as note here.

Modern Editor :-

To convert to a Modern editor Go To ‘View all power Automate settings’ and enable “Experimental features”

Now the view of the Expression editor will be displayed in Modern Mode.

Replace:- will be used to replace a string with another string.

The output will be displayed as “the new string” where the string “old” is replaced with string “new”

Substring :-

It will display the substring of a string for that we need to indicate the the range of the string

Here i indicated the range between 0 to 5 in a string.

The output will be shown below

Nested Expression in Concatenate Expression :-

Here i have Nested some expressions like Guid(),toLower() and toUpper() in concatenation Expression.

The outputs for that Expressions is as shown below.

Split() :- This will split the Strings individually

The following output will show the individual strings

Indexof() :-

it will display the index of the string.

The index of “t” is 2

LastIndexof() :-

It will display the index of particular letter from the last

The index of “a” in the above string is 11

Startswith() :-

It just checks our string’s starting letter/letters. it just pass a true or false output

The “po” is the starting letters of our string so it returns true

trim() :-

It will trim the part

Here the trim action has trimmed the white spaces in the string.

Logical and Mathematical Functions :-

First initialize a variable as string type

Then add a compose action

Contains() :-

It just checks the value is included in the string or not

Here the word “Reza” is included in the string so it returns true

Equals() :-

It just checks the word is equal to the string or not

Here the variable is equal to the string so it returns true

and() :-

it checks the two strings or Expressions and return true when both are true

Here the both Expressions are true so it returns true

Use of these Expressions in a condition :-

First add condition action to the flow

When the “and” function is equal to true the flow will trigger in yes condition otherwise it will direct to the no condition

In “yes” condition i have added some Expressions they are

Minimum function

Maximum function

random function

range function

After the flow runs the condition gets triggered and now the yes condition will execute.

The minimum digit of the array is 1

The maximum digit of array is 9

The random digit between 0 to 500 is 465

The range of digits between 0 to 10 will be displayed

Date Functions :-

Concatenation function will concatenate the two values or strings

Utc() :- it will display the coordinated universal time

Format date time :-

The time format can be set manually

Convertfromutc() :-

It will convert The utc time into central standard time.

Add days() :-

it will add the extra days to present date and will return the output

Subtract can be done using same function but we just need to indicate ” -” symbol before the digit. then it will subtract the the date and pass the result.

DayofWeek() :-

it will display the day of this week

Collection Functions :

Here i have declared 3 compose actions and in first 2 compose actions i have passed an arrays & in 3rd compose action we will perform some functions.

Contains() :-

It just checks that our string contains a value in the function which we declared.

Then it will return true or false in the result.

Length() :-

Length of our string will be displayed in the output.

Empty() :-

It just checks our string is empty or not if it is empty it will return true otherwise it will return false

First() :-

It will return the first string of an array

Last() :- It will return the last string of an array

Skip() :-

The skip function will skip some strings and display the Result

Here the first string has skipped

Interaction () :-

It will filter the common value in both the strings

Here the common value is “BMW”

Union() :-

It will union both the strings or arrays

The union of both arrays is shown below

Best Practices :-

1.Power automate reads and processes dates and times in coordinated universal times UTC

2.Rename actions with meaningful names (since these names would be used in Expressions

3.Add Expressions as notes to actions and conditions (Makes it easy to read the underlying expressions

4.use peek code to check for expression syntax(peek code is your friend)

5.use the ? for reading optional properties from JSON objects

6.[] array notations in JSON objects

7.when updating Expression , make sure to hit the update button (classic editor)

Leave a Reply

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