“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.
Take the whole email body, and split it by the ‘<table’ string, the opening tag of an HTML 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.
Return back the opening and closing tags that were removed with the split(…) expressions.
concat('<table', outputs('Compose_2'), '</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.
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.
6 thoughts on “Parse data from an HTML table in an email with Power Automate”
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?
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(…, ‘
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
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.
xml(table_html) doesn’t transform anything. you need pure html tags without class added by outlook.
Hello, everything works for me except the last step: it does not convert anything to XML.