Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

How to combine expressions in your Power Automate flows

Posted on May 18, 2022May 18, 2022 by Tom

“I know what the expression should do, I just don’t know how to build it! What Power Automate expressions should I use and how to combine them?”


Using expressions is similar to using the existing Power Automate actions. You’ve got these small building blocks, each of them with some functionality, and you combine them together to do a specific task.

While the designer makes it easy to drag and drop actions, with expressions it’s mostly on your shoulders. It gives you more freedom, you’re not limited by the existing actions, but you get also more responsibility. Unless you use the right expression or combination of multiple expressions, the flow won’t work. 

How do you then build the right expression from the small building blocks?

Follow your thought process

Let’s show it on an example – a PDF file with a date in the name, e.g. Tom_Riha_overview_13/05/2022.pdf, and the goal is to rename the file while changing the date format: 2022-05-13_Tom_Riha_overview.pdf. How would you do that using expressions?

Isolate the date string

The first step would be to isolate the date. But Power Automate won’t “just look and see the date”, it doesn’t even know there’s a date. Power Automate sees the whole file name as a text with various characters. If you look on it in the same way, you’ll notice that the date is after the last underscore character. The extraction will take two steps – split(…) the string by the underscore:

split('Tom_Riha_overview_13/05/2022.pdf', '_')

and take only the last(…) value:

last(split('Tom_Riha_overview_13/05/2022.pdf', '_'))

You just reduced the string to: 13/05/2022.pdf. It removed big part of the text, but it still has the file extension. Following the same logic, you can split(…) the result again, this time by a comma:

split(last(split('Tom_Riha_overview_13/05/2022.pdf', '_')), '.')

and take only the first(…) part:

first(split(last(split('Tom_Riha_overview_13/05/2022.pdf', '_')), '.'))

The result of this expression will be the date string alone: 13/05/2022.

Power Automate combine expressions

Convert the string to a date

You know it’s a date and as such it’s easy for you to change its format. But again, Power Automate doesn’t know that it’s a date. That the 13 represents day, 05 month, and 2022 a year. You must tell it that it’s a date and in what format with the parseDateTime(…) expression:

parseDateTime(first(split(last(split('Tom_Riha_overview_13/05/2022.pdf', '_')), '.')), 'en-US', 'dd/MM/yyyy')

Format the date

Now, when the flow knows that the string represents a date and what date it is, you can change its format with the formatDateTime(…) expression:

formatDateTime(parseDateTime(first(split(last(split('Tom_Riha_overview_13/05/2022.pdf', '_')), '.')), 'en-US', 'dd/MM/yyyy'), 'yyyy-MM-dd')

Get the original text and the file extension

You’ve got the date in the right format, what’s left is to add the remaining text from the file name. Again, you must tell the flow which part of the text it should add, it doesn’t know that it already processed the date.

You can use the same approach as when isolating the date. Split(…) by underscore:

split('Tom_Riha_overview_13/05/2022.pdf', '_')

take(…) the 3 pieces before the date:

take(split('Tom_Riha_overview_13/05/2022.pdf', '_'), 3)

and join(…) them back into a string using underscore as the delimiter:

join(take(split('Tom_Riha_overview_13/05/2022.pdf', '_'), 3), '_')

You’ll get also the file extension with a similar approach:

last(split('Tom_Riha_overview_13/05/2022.pdf', '.'))

Put all the pieces together in a single expression

Use the concat(…) expression to put all the pieces together to build the new file name.

concat(
formatDateTime(parseDateTime(first(split(last(split('Tom_Riha_overview_13/05/2022.pdf', '_')), '.')), 'en-US', 'dd/MM/yyyy'), 'yyyy-MM-dd'),
    '_',
    join(take(split('Tom_Riha_overview_13/05/2022.pdf', '_') ,3), '_'),
    '.',
    last(split('Tom_Riha_overview_13/05/2022.pdf', '.'))
)
Power Automate combine expressions

Summary

The final expression probably looks scary, but all we did was to follow a thought process and combine the steps into Power Automate expressions. Slowly, step by step, without any assumptions, using only the visible data. It is maybe a bit extreme example and your expressions will be simpler, but learning to combine expressions together will make it easier to build any flow.

That’s why I included also some common combinations of the expressions into the expressions cheat sheet.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

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

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

  • How to find Excel rows missing in SharePoint list (Power Automate)March 29, 2023
  • Check whether user exists in AAD with Power AutomateMarch 26, 2023
  • How to highlight whole SharePoint row based on calculated dateMarch 22, 2023
  • Why is your Power Automate flow running so slow?March 19, 2023
  • How to add multiple links to the Power Automate approval taskMarch 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes