Power Automate - Expressions

wyattdave

david wyatt

Posted on October 28, 2024

Power Automate - Expressions

Is Power Automate Low Code or Now Code, that is an interesting question, and its somewhere in the middle. Its probably closer to no code, as it is definitely possible to create flows that just use the drag and drop ui and input configs. But expressions mucky the water a little, as they are code, but not real code, or are they?

Expressions are incredibly powerful and something that new developers often do not use enough, just like Excel can be used without formulas, would you really want to?

There are a couple of key things to know about when using expressions:

  1. What expressions are there
  2. When to use them
  3. Quick tips

1. What expressions are there

Power FX is the 'language' of the Power Platform, but not for Power Automate. If you didn't already know, Power Automate is actually a Azure Logic App dressed up in a nice suit. The schemas are Logic Apps, the run engine is a Logic App, the connectors by defualt work on both, and guess what, expressions are Logic App expressions.

So if you want a full list of expressions you have to look for Logic App expressions.

logic app ms learn

They may have added Power Automate to the title, but the url path tells it all 😎

https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference

So if you want to find this, google logic app expressions.

There are as of now (October 2024) 143 expressions, split into 10 sections

  • String
  • Collection
  • Logical Comparison
  • Conversion
  • Data conversions/Math
  • Date time
  • Referencing
  • Workflow
  • URI parsing
  • Manipulation

and in most cases there will be an expression for exactly what you need. The best ways to find the right one is

The UI will list all expressions and provide simple descriptions.

expression ui

2. When to use them

Trick question, the answer is always 😎

The reason is using expressions instead of actions its the key to good flow design. Although there are readability benefits to using actions, using expressions improves performance and saves api calls (which is becoming more important as time goes on).

Some common examples are:

Conditions

Action
Most common one I see, condition actions are good for different logic but expressions should be used for variables.

condition action

Expression
condition expression

Time

utcNow() is such a simple expression I have no idea why the Current Time action exists.
Action
time action

Expression
time expression

Add Time

Another really simple expression, along with addMonths(), addDays(), addHours(), addSeconds(), addToTime(), getPastTime(), getFutureTime().
Action
add time action

Expression
add time expression

Format Number

formatNumber() does exactly the same as the action, so again no idea why the action exists.
Action
format action

Expression
format expression

3. Quick tips

Under the hood the way Power Automate knows the input is a expression and not a string is it wraps it in @{}. The @ indicates an expression, and the } the end. This means you cant have a string with just @, you have to escape it with itself (@@), this is normally automatically done by the ui.

@ string

@@ in code

This is why you cant just type an expression in, but have to go through the expression menu, because if you do it escapes the @.

expression in string

But you can copy and paste an expression in, so anything complex with multiple nested expressions is easier in a text editor:

copy paste expression

While talking about copying, copying expressions between actions can be temperamental, with sometimes it just copying the label. To get around this you can peak the code and copy the expression from there:

copy peak

The peak code is also great for when you want to use an expression to set a input, as the ui often shows display names but inputs a guid.

get items

As an example check out this Get Items, it looks like the List Name is 'Test list' but if you used an expression that set the list by its display name it wouldn't work. If you peak the code you will see why, as the actual input (named table in the code) is the list guid, with the ui showing the display name to make it easier to select.

get items peak code


As you can see expressions give Power Automate its real Power, and its something you should definitely invest learning in.

💖 💪 🙅 🚩
wyattdave
david wyatt

Posted on October 28, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Power Automate - Expressions
powerautomate Power Automate - Expressions

October 28, 2024

Exception Handling in Power Automate
powerautomate Exception Handling in Power Automate

January 18, 2023