7 Expressions

7 one line expressions that could help you in Power Automate

Small expression box

Have you ever wondered why the Expression box in Microsoft Flow is so small?

Low code expressions

It is because Flow is a low code product and low code means that we don’t need much code. Often a one liner can do the job.

Sometimes it is the small things in power Automate that make it difficult to get the job done! In this post I’m looking at 10 one-line expressions that can help. Most of these on liners will fit in that small expression box.

Expression 1 – Get your workflow run URL

This is one of my favourites that couldn’t miss from this list. Once you created a compose action and set this to


Then you can use the following expression to build the url of the current run of the flow.


For more details see my post about finding your run Url.

Expression 2 – Format your dates

Formatting dates is easy in Power Automate

formatDateTime(utcNow(), 'yyyy-MM-dd')

Also see How to find your overdue tasks?

Expression 3 – Get the last X characters from a text

Getting the first X characters is easy using the substring function. The last X characters is slightly harder especially if you don’t know how long the text is. The following expression is your answer:

substring(outputs('Compose'), sub(length(outputs('Compose')), 4),4)

Last 4 characters

Expression 4 – Get that space into a variable

When you set a variable to a space Flow will tell you that the value is empty. the following expression will help you set a variable to a space.

replace("X","X"," ")

Expression 5 – Fix those failing switches

When you use switches in Flow and the switch value is sometimes not set you will find that your flow will fail. If you use the coalesce function you can make sure that you always get a value from a variable or action output. Even if the variable or output isn’t set.

Coalesce function


For more information see Improve your switches.

Expression 6 – Compare those texts

How often do you need to check the value of a text variable or output. A while back I was looking at the extensions of a file name

The below expression returned false:

equals('Pdf', 'PDF')

In the above example I used variables, but for simplicity sake I’m using hard coded strings. To solve my problems I used the toUpper fuction:

equals(toUpper('Pdf'), toUpper('PDF'))

Expression 7 – Have you got any great expressions?

The last expression spot in this post is still available. Have you used any great expressions? Please leave you useful one liners in the comments below.

12 thoughts on “7 one line expressions that could help you in Power Automate

    1. It would very much depend on the kind of data you would want to extract and the format of the email. I’m not sure that I could give you simply expression for this. You could of course create an Azure function that does the work for you using regular expressions. Then call this function from a flow.

  1. What ist the best way to handly long expressions? Using a text editor? Is there an editor with intelliSense?

  2. I used coalesce(triggerBody()?[‘Stage’],’value’) yet does not display the value from the list but displays the word value in the email notification.Please help
    My Stage column is a Choice data type

    1. Hi Chinama,

      You will find that in your case the triggerBody()?[‘Stage’] isn’t a null value. Most likely You will get something like []. Is your Choice field a multi select choice or is it a single choice?

  3. Hi Pieter.

    Great insights and info.
    This is sort of a one-liner. I use SELECT to sanitize a string:
    The below expression will create an array of characters from the string which are alphanumeric, including “-“,’/”,”\” and space.

    To get it back to a string I join this output with a ‘#’ and then replace ‘#’ with ”

    (OK. it’s a three liner)

    From: range(0, length(variables(‘invoiceNo’)))
    Map: if(
    or (
    or (
    or (
    and(greaterOrEquals(substring(variables(‘invoiceNo’), item(), 1),’a’),lessOrEquals(substring(variables(‘invoiceNo’), item(), 1),’z’)),
    and(greaterOrEquals(substring(variables(‘invoiceNo’), item(), 1),’A’),lessOrEquals(substring(variables(‘invoiceNo’), item(), 1),’Z’))
    and(greaterOrEquals(substring(variables(‘invoiceNo’), item(), 1),’0′),lessOrEquals(substring(variables(‘invoiceNo’), item(), 1),’9′))
    equals(substring(variables(‘invoiceNo’), item(), 1),’-‘)
    equals(substring(variables(‘invoiceNo’), item(), 1),’ ‘)
    equals(substring(variables(‘invoiceNo’), item(), 1),’\’)
    equals(substring(variables(‘invoiceNo’), item(), 1),’/’)
    ,substring(variables(‘invoiceNo’), item(), 1),”)

  4. I’m not an expert on this, so not sure how the split could work into this? I would have to split on the acceptable chars? I really didn’t want to split the whole array and then loop char by char, as we know in Power Automate/Flow, iteration is not a strong point.

  5. How do I get the Error Details when a flow fails, so I can send those details back to the submitter of the flow.
    For instance, I’m trying to set the permissions to a document to read only, but the FLOW errors our because the document is locked for shared use by a user xxx. I can see that error if I look at the error details of the failed FLOW, but I want to email that error on the FLOW Failure.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: