web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Pulling info from emai...
Power Automate
Unanswered

Pulling info from email body into Excel.

(0) ShareShare
ReportReport
Posted on by 20

Hi everyone! 

 

I'm currently building out a flow to pull basic customer information from an email body and put it into an excel spreadsheet.

I was able to get the trigger to work correctly, the only issue I'm running into is pulling the correct info from the email and displaying it in excel. 

 

I think where I messed up is with the expressions. I've attached a screenshot of the current flow that I have built out and screenshot of the data that has been pulled into my excel sheet. As you can see it's only pulling a phone number. If someone can help write the right expressions that would be much appreciated.

 

Thanks!

Categories:
I have the same question (0)
  • rzaneti Profile Picture
    4,241 Super User 2025 Season 2 on at

    Hi @tommyd369 ,

     

    Could you please share a sample of the email content from where you are trying to extract the data? Please also share the full text of one or two of the expressions that you are using to populate the Excel table.

     

    Also, to learn a little more about how to use Power Automate to extract data from texts (including emails), check this article that I recently wrote: http://digitalmill.net/2023/08/12/how-to-extract-and-clean-texts-with-power-automate/ 

  • tommyd369 Profile Picture
    20 on at

    Of course, I've attached the screenshots down below so you can get a better idea of what I'm trying to do.

    tommyd369_0-1694445973243.png

    Caller ID Expression: 

    first(skip(split(first(split(body('Html_to_text'),'Caller ID')),': '),1))
     
    First & Last Name Expression: 
    first(skip(split(first(split(body('Html_to_text'),'First and Last Name')),': '),1))
     
    Phone Number Expression: 
    first(skip(split(first(split(body('Html_to_text'),'Phone Number')),': '),1))
     
    Email Expression: 
    first(skip(split(first(split(body('Html_to_text'),'Email')),': '),1))
     
    File ID number expression: 
    first(skip(split(first(split(body('Html_to_text'),'File ID Number')),': '),1))
     
    Additional Info Expression:
    first(skip(split(first(split(body('Html_to_text'),'Additional Info')),': '),1))
  • rzaneti Profile Picture
    4,241 Super User 2025 Season 2 on at

    Hi @tommyd369 ,

     

    Apparently your expressions were incorrect. I took this text based on your template as example:

    rzaneti_0-1694469154467.png

     

    And after run 3 of the expressions, the results were all the same:

    rzaneti_1-1694469176645.png

     

    The expression starts to run from the most internal command, and achieve the external ones at last. In your case, taking the 'Caller Id' as example, you are doing the following:

    • Splitting the text by 'Caller ID' (which is an error, as the text that you should capture is 'CallerID', without space) (red)
    • Accessing the first element from the generated array, which is everything before the 'Caller ID' substring (and here is one other error: you should be accessing everything after this separator) (blue)
    • After taking this first part, you split it again, but now for ":", resulting in a new array (orange)
    • Then you generate a new array from its second element to the end(green)
    • And finally you return this first element

     

    Expression: first(skip(split(first(split(body('Html_to_text'),'Caller ID')),': '),1))

     

    I wrote a different expression template that may be a little easier to apply. Here is an example of the expression to access the Caller Id:  trim(first(split(last(split(body('Html_to_text'), 'CallerID:')), 'First and Last')))

     

    To replicate it to the rest of the elements that you need to extract, just replace the green text for the element that you want to extract, and the red for the first element after it. For example: if you want to return the 'File ID Number', replace the green for 'File ID Number' and the red for 'Additional Information'.

     

    Also, make sure to add the ":" when writing the green text, otherwise your final output will look like this:

    rzaneti_3-1694470017557.png

     

     

    This is the output of the flow, when using this expression template:

    rzaneti_4-1694470038663.png

     

    As a final recommendation, make sure to always include a 'trim' as external expression when you are working with text extraction. It will prevent you to pull extra blank spaces at the beginning or at the end of the extracted text (the trim transforms ' Mailer Inquires ' into 'Mailer Inquires', without the extra spaces at beginning/end).

     

    Let me know if it works for you or if you need any additional help!

     

    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

    http://digitalmill.net/ 

  • tommyd369 Profile Picture
    20 on at

    I Implemented what you said. The phone number and File ID came in correctly but the rest pulled more data than what's needed.

     

    Here are the expressions that I used down below:

     

    Caller ID: 

    trim(first(split(last(split(body('Html_to_text'), 'CallerID:')), 'First & Last Name')))
     
    First & Last Name: 
    trim(first(split(last(split(body('Html_to_text'), 'First & Last Name:')), 'Phone Number')))
     
    Email: 
    trim(first(split(last(split(body('Html_to_text'), 'Email:')), 'File ID Number')))
     
    Additional Info:
    trim(first(split(last(split(body('Html_to_text'), 'Additional Info:')), '')))
     
    I wasn't sure what to put at the end of the additional info expression since there isn't an element being pulled after it.
     
    I've also attached a screenshot of the excel sheet so you can see what data is being pulled.
     
    tommyd369_0-1694538477708.png

     

  • rzaneti Profile Picture
    4,241 Super User 2025 Season 2 on at

    Hi @tommyd369 ,

     

    You actually don't need to add the variables: I just used them in my example to display the output from the expressions. You can use the provided expressions directly to each of your inputs from 'Add a row into a table' action, just replacing the expressions that you first inserted. 

  • tommyd369 Profile Picture
    20 on at
    Everything is working, the only issue I'm having is it keeps pulling a link into the additional info column. I'm not exactly sure how to fix this.

     

    This is the current expression I'm using for additional info:

    trim(first(split(last(split(body('Html_to_text'), 'Additional Information:')), '')))
     
    I've also included a screenshot of my sheet as well.
     
    tommyd369_0-1694548331647.png

     

  • rzaneti Profile Picture
    4,241 Super User 2025 Season 2 on at

    Hi @tommyd369 ,

     

    Just to confirm, will your template always have a line break between the 'Additional info' and this link? If yes, you can use this expression: trim(first(split(last(split(body('Html_to_text'), 'Additional Information:')),decodeUriComponent('%0A'))))

     

    The only difference from your expression is the use of 'decodeUriComponent('%0A')' as text to delimit the extracted data. We use this method when we need to refer to line breaks in Power Automate. If your 'Additional info' can have multiple lines, the best approach will be to set the '[' as final separator, so the expression will look like this: trim(first(split(last(split(body('Html_to_text'), 'Additional Information:')), '[')))

     

    Let me know if any of these approaches solve the problem!!

     

  • tommyd369 Profile Picture
    20 on at

    That fixed it, Thank You!

  • tommyd369 Profile Picture
    20 on at

    I apologize for all of the questions.

     

    I recently duplicated this flow and added one additional columns. I used the same expressions you gave me but for some reason every time I try and run it, I keep getting an error that says "This won't work because it would move cells in a table on your worksheet."

     

    I tried clearing the data and resizing the table based on the other support threads that I read but I still keep getting the same error.

     

    Do you know why this is and how I might be able to fix it?

  • rzaneti Profile Picture
    4,241 Super User 2025 Season 2 on at

    Hi @tommyd369 ,

     

    First, don't worry: we are here to help and you can ask as many questions as you need!!

     

    About your issue, it looks to be more related to your inserting rows into the table process, than to the expressions. I have some questions for you:

    - After duplicate the flow, did you turned the old one off?

    - Are you inserting the new row into the same table and file as the old flow?

    - Does your Excel file have any populated cells below the table range?

    - When you click anywhere into this new column that you created, can you see the "Table" tab in Excel ribbon?

     

    Based on your answers, we may be able to identify the issue!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard