Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Triggers
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
  • Get help with flow
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.


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.

3 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
  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

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!


NEW! Master the HTTP requests to SharePoint with a new 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.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Use Power Automate to forward Outlook events upon registrationJanuary 29, 2023
  • Why the condition is false for the same numbers (Power Automate)January 25, 2023
  • How to forward event invitation to other calendar (Power Automate)January 22, 2023
  • Run ‘For selected item’ flow from non-default environment (Power Automate)January 18, 2023
  • Hide button in SharePoint list after Power Automate flow startedJanuary 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes