This post is inspired by following Microsoft Tech Community conversation:
https://techcommunity.microsoft.com/t5/PowerApps-Flow/Naming-of-attachments-in-Flow/m-p/874218
Using Power Automate, Outlook attachments are being saved to SharePoint. Attachments need to be renamed based on extracted text from the email subject line. For example: “text1 text2 11849850 – text3”
The part of the Flow that I am interested in will extract text using the SPLIT, FIRST and LAST functions.
The SPLIT function breaks a string into a table of sub-strings based on a specified delimiter. Using our example from above and specifying a space (“ “) as the delimiter:
Formula | Result |
split('text1 text2 11849850 – text3', ' ') | [“text1″,”text2″,”11849850″,”-“,”text3”] |
The FIRST function returns the first record of a table.
Formula | Result |
first(split('text1 text2 11849850 – text3', ' ')) | text1 |
The LAST function returns the last record of a table.
Formula | Result |
last(split('text1 text2 11849850 – text3', ' ')) | text3 |
To get “11849850” out of “text1 text2 11849850 – text3” we have to break down the string into its parts and filter out what we don’t need. Within Flow:
- Initialize a variable called varEmailSubject to store the example text

- Remove the hyphen by initializing another variable called varSubject using the following expression:
split(variables('varEmailSubject'), ' - '))

- Remove “text3” using the FIRST function in the varSubject action with the following updated expression:
first(split(variables('varEmailSubject'), ' - '))

- Remove “text1” and “text2” using SPLIT in the varSubject action:
split(first(split(variables('varEmailSubject'), ' - ')), ' ')

- Finally, use LAST in the varSubject action to get the target value:
last(split(first(split(variables('varEmailSubject'), ' - ')), ' '))

The final formula looks complicated but once broken down into its smaller parts its more manageable.
Thanks for stopping by.
Norm
One thought on “Tech Community: Naming attachments”