Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

Parse data from an HTML table in an email with Power Automate

Posted on August 24, 2022August 24, 2022 by Tom

“I receive an email with data summary in a table, how can I parse the data from there using Power Automate flow?”


One of the most promoted use cases for Power Automate is email processing. You receive an email with an attachment and it’ll save the attachment to OneDrive. But often it’s not that simple. You might want to look for a specific attachment or a specific keyword in the subject, and even then just saving the attachment might be not enough. There’s also the email text which can contain relevant information. While it can be often extracted using the ‘HTML to Text’ action, it doesn’t work that well for tables.

How do you then extract data from a table?

Find the table

The first step to extract data from a table is to find the table. It doesn’t matter if it’s one or more tables, you must always find the right one, e.g. the one with ‘Table2’ in the header.

Power Automate parse email table

Take the whole email body, and split it by the ‘<table’ string, the opening tag of an HTML table.

split(triggerOutputs()?['body/body'],'<table')
Power Automate parse email table

The result won’t look pretty, but it doesn’t matter, it’ll give you each table as a separate item in an array.

Now you can search for the table based on some value. The whole table is a single item so you can use ‘Filter array’ action to search for that value (which must be unique!), e.g. ‘Table2’.

The result should be a single item with the table string.

Isolate the table

But at this moment it still contains more than just the table, it can contain all the other HTML tags before the next ‘<table’ string. To extract only the table, take the first output from ‘Filter array’. Use another split(…) expression, this time splitting by the closing table tag ‘</table>’, and take everything before that.

split(first(body('Filter_array')),'</table>')[0]

Return back the opening and closing tags that were removed with the split(…) expressions.

concat('<table', outputs('Compose_2'), '</table>')
Power Automate parse email table

That’ll give you a complete HTML table, convertible into XML with the xml(…) expression.

Once you have an XML, you can use xpath(…) to pick the desired value.

Summary

As you can see, it’s not complicated to parse data from an email with an HTML table using Power Automate. Using the HTML tags you can split(…) the email into pieces, extract and rebuild only the desired table, and extract the values directly with the xml(…) and xpath(…) expressions.


πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

14 thoughts on “Parse data from an HTML table in an email with Power Automate”

  1. Jim Ledger says:
    November 21, 2022 at 5:30 pm

    Thank you for this. It all works great until the last step where I get an error because the table contains image tags which are not closed, so it says the opening tag does not match the closing tag:

    How might you suggest I remove all the image tags?

    Many thanks

    Reply
    1. Tom says:
      December 5, 2022 at 7:51 pm

      Hello Jim,
      some time ago I tried to get rid of these tags but I didn’t find any good solution. I tried replacing them, e.g. replace(…, ‘

      Reply
      1. Nick says:
        February 20, 2024 at 10:58 am

        Thank you very much for the instructions!

        The last step gives me the error

        “InvalidTemplate. Unable to process template language expressions in action ‘Compose_4’ inputs at line ‘0’ and column ‘0’: ‘The template language function ‘xml’ parameter is not valid. The provided value cannot be converted to XML: ”\’ is an unexpected token. The expected token is ‘”‘ or ”’. Line 1, position 14.’. Please see https://aka.ms/logicexpressions#xml for usage details.’.”

        What can I do?

        Thank you!

        Reply
        1. Tom says:
          March 17, 2024 at 1:05 pm

          Hello Nick,
          you can try to google some XML parser and put the output of ‘Compose_3’ into the parser to tell you what’s wrong with the XML, there might be some character that must be removed based on the error message.

          Reply
  2. rathnasiri says:
    January 29, 2023 at 7:52 am

    I am new to power automation flow,

    how to pick 1 table (multiple tables in compose like 1.. 10) I want to get 4th table data to extract

    Reply
    1. Tom says:
      February 9, 2023 at 9:32 pm

      Hello rathnasiri,
      that’s a bit complicated for a comment response, I might write a post on this topic in the future, but for now I’m sure there’ll be some videos on Youtube how to parse emails.

      Reply
  3. y_59 says:
    February 2, 2023 at 2:12 pm

    xml(table_html) doesn’t transform anything. you need pure html tags without class added by outlook.

    Reply
  4. Nick says:
    May 24, 2023 at 11:43 am

    Hello, everything works for me except the last step: it does not convert anything to XML.

    Reply
    1. Tom says:
      August 12, 2023 at 10:23 pm

      Hello Nick,
      that’s hard to tell without seeing the email as each email is different, you’ll have to try and play with it a bit.

      Reply
  5. Nivedhana S says:
    February 27, 2024 at 7:39 am

    Hello,

    Great blog. Managed to get table out of the email following the steps. The output is now is in XML format. I need to add this table to an excel file. Is that possible?

    Reply
    1. Tom says:
      March 17, 2024 at 1:18 pm

      Hello Nivedhana,
      I have no idea, never needed to convert XML table into Excel.

      Reply
  6. Bach Nguyen says:
    September 14, 2024 at 6:58 am

    Hello
    Thank you for sharing. I’m stuck in “filter array” step. I can’t call the Dynamic “Item” to compare, it only show the output of compose before. can you help me

    Reply
    1. Nuno Figueiredo says:
      November 13, 2024 at 11:33 pm

      Same issue for me

      Reply
    2. Silja says:
      March 7, 2025 at 4:02 pm

      Go to ‘Edit in advanced mode’ and type the following

      @contains(item(), ‘[text to find]’)

      Reply

Leave a Reply Cancel reply

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

πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Working on an Approval process?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy a fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundleβ€”everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes