It’s easy to load information directly from Exchange Online into Power Query. That is, e.g. email lists and information about them, but also information about the calendar, etc.

How to do it?

In Power BI, you connect to a resource called “Exchange online”.

Use Power Query to get data from email folder, calendar etc. (Exchange)

Excel doesn’t have this option, but it doesn’t matter – we can select an empty query and write something like:

Use Power Query to get data from email folder, calendar etc. (Exchange)

And that’s all. Then you just choose what interests you and that’s it.

Use Power Query to get data from email folder, calendar etc. (Exchange)

Výsledky (např. maily) je třeba libovolně filtrovat. Je také dobré si uvědomit, že v mailech jsou dostupné i přílohy – můžete se takto přímo dotázat třeba do konkrétní tabulky (xlsx, csv…), která přišla mailem, a zobrazit její hodnoty. Např. takovýto kód vám vytáhne nejaktuálnější mail s určitým předmětem a z jeho přílohy vytáhne příslušný obsah.

let
   Source = Exchange.Contents(“beran@exceltown.com”),
   Mail = Source{[Name=”Mail”]}[Data],
   filter_subject = Table.SelectRows(Mail, each ([Subject] = “Aktuální přehled situace“),
   filter_latest = Table.SelectRows(filter_subject, let latest = List.Max(filter_subject[DateTimeReceived]) in each [DateTimeReceived] = latest),
   list_of_attachments = Table.ExpandTableColumn(filter_latest, “Attachments”, {“AttachmentContent”}, {“AttachmentContent”}),
   attachment_content = list_of_attachments{0}[AttachmentContent],
   list_of_sheets = Excel.Workbook(attachment_content),
   data = list_of_sheets{[Item=”prehled aut“,Kind=”Sheet”]}[Data]
in
   data