Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
plutoforever
Frequent Visitor

Help with adding date to html.table M function when scraping Outlook email

Spoiler

I have created a Microsoft Exchange connection in PowerBI to be able to scrape an HTML table each day from a specific Outlook email I receive.  I am able to successfully extract the table into an actual table format I can then join to using Html.table.  However, when I create this new Html.table I lose the DateTimeSent column showing when the email came in:

plutoforever_0-1685022341726.png

 

How would I rejoin this to the end table so the end user can filter on the date to show just the data from an email from a specific day?  Here is the M code I am using (:

 

let
Source = Exchange.Contents(""),
Mail1 = Source{[Name="Mail"]}[Data],
#"Filtered Rows" = Table.SelectRows(Mail1, each Text.Contains([Subject], "Optigistics Today - Error")),
#"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each ([Folder Path] = "\Inbox\")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Sender", "DisplayTo", "DisplayCc", "ToRecipients", "CcRecipients", "BccRecipients", "DateTimeReceived", "Importance", "Categories", "IsRead", "HasAttachments", "Attachments", "Preview", "Attributes", "Id"}),
#"Expanded Body" = Table.ExpandRecordColumn(#"Removed Columns", "Body", {"TextBody", "HtmlBody"}, {"TextBody", "HtmlBody"}),
#"Cleaned Text" = Table.TransformColumns(#"Expanded Body",{{"HtmlBody", Text.Clean, type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Cleaned Text", "HtmlBody", Splitter.SplitTextByDelimiter("<div class=MsoNormal align=center style='text-align:center'><hr size=2 width=""100%"" align=center></div>", QuoteStyle.None), {"HtmlBody.1", "HtmlBody.2", "HtmlBody.3"}),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"HtmlBody.1", type text}, {"HtmlBody.2", type text}, {"HtmlBody.3", type text}}),
#"HTML Table" = Html.Table(#"Changed Type"{0}[HtmlBody.3],
{{"col1","td:nth-child(1)"},
{"col2","td:nth-child(2)"},
{"col3","td:nth-child(3)"},
{"col4","td:nth-child(4)"},
{"col5","td:nth-child(5)"}},
[RowSelector="tr"]),
#"Promoted Headers" = Table.PromoteHeaders(#"HTML Table", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Error Code", Int64.Type}, {"Severity", type text}, {"ID", Int64.Type}, {"Customer Number", Int64.Type}, {"Error Message", type text}})
in
#"Changed Type1"

1 ACCEPTED SOLUTION
plutoforever
Frequent Visitor

I was able to achieve what I needed embedding the Html.Table inside a Table.AddColumn which created a new table column that I could expand while keeping all other columns from the email including the email date one.  The added benefit is with the following code the "each Html.Table" it brought in all new emails where just the "Html.Table" only brought in the most recent.

 

#"Added Custom2" = Table.AddColumn(#"Added Custom", "Custom2", each
Html.Table([HtmlBody.3],
{{"Col1","td:nth-child(1)"},
{"Col2","td:nth-child(2)"},
{"Col3","td:nth-child(3)"},
{"Col4","td:nth-child(4)"},
{"Col5","td:nth-child(5)"}},
[RowSelector="TABLE > * > TR"])),

View solution in original post

1 REPLY 1
plutoforever
Frequent Visitor

I was able to achieve what I needed embedding the Html.Table inside a Table.AddColumn which created a new table column that I could expand while keeping all other columns from the email including the email date one.  The added benefit is with the following code the "each Html.Table" it brought in all new emails where just the "Html.Table" only brought in the most recent.

 

#"Added Custom2" = Table.AddColumn(#"Added Custom", "Custom2", each
Html.Table([HtmlBody.3],
{{"Col1","td:nth-child(1)"},
{"Col2","td:nth-child(2)"},
{"Col3","td:nth-child(3)"},
{"Col4","td:nth-child(4)"},
{"Col5","td:nth-child(5)"}},
[RowSelector="TABLE > * > TR"])),

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors