Skip to main content

Analyzing your Microsoft Exchange Account Data with Power Query

Headshot of article author The Power BI Team

One of the interesting additions to the Power Query Preview December update is the ability to import data from Microsoft Exchange. In this blog post, Miguel Llopis (a Program Manager in the Power Query team) will walk us through the capabilities exposed by this new feature and show how you can easily do analytics on top of your Exchange account.

Connecting to Exchange using Power Query

If you have installed the latest Power Query Preview update you will be able to connect to Microsoft Exchange via the “From Other Sources” menu in the Power Query ribbon.

Connect to Microsoft Exchange via From Other Sources menu 

After selecting this option, you will be prompted for your Exchange account credentials. Once you provide credentials the Navigator side pane will show the list of items available in your Exchange account, including Mail, Calendar, People, Tasks and Meeting Requests. You can use the Navigator to preview and select one or more items from this list. The Navigator will then let you load these items directly into the workbook or apply some filters and transformations before loading.

Navigator side pane shows list of items available 

In this case, we will select “Mail” and click “Edit”, so we can apply filters and transformations to our query before downloading the Mail data from Exchange. The Query Editor will show us a preview of the Mail items in my account, where we can apply any table transformations available in Power Query just as we do with data coming from other sources like databases or files.

Query Editor displays preview

Analyzing emails sent directly “to me” per day

To showcase some of the possible analytics that we could build, we will create a query that returns the number of emails sent directly to me by day.

You can see how the first column in the table contains the Folder Path information for each Mail item. In this case, my Exchange account has a set of rules and it sends the items that contain my email address in the “To” line to a certain folder (“ToMe”). We can filter this column to only include items in this folder, by using the Filter menu in the column header. You will notice that, because I have too many items in the Inbox folder, the filter values list only displays “Inbox” initially, since the Query Editor only uses a sample of the data for preview and transformation purposes, but there is a way for us to load up to the top 1,000 distinct values in this column by using the “Load more” link at the bottom of the filter menu.

Load top distinct values using Load More link 

After loading more items, I can search for the “ToMe” folder and apply the desired filter.

 Search for the To Me folder

Note that even if you don’t have custom rules and a folder structure to organize your mail, you can also achieve the goal of filtering down to only include emails with a certain recipient in the To line by expanding the “ToRecipients” column in this table and filtering by email address.

Now that we have filtered down to only the items that we want to analyze, let’s apply some extra transformations so we are able to group these items by received date. Notice that the table contains a “DateTimeReceived” column that we can use. In this case, since we want to group just by received date and not date/time, we will need to change the type of the “DateTimeReceived” column to Date. In order to do that, we can select the column and use the Data Type menu in the ribbon to set the column type to Date.

 Select the column and use the Data Type menu

Let’s also rename this column to “Date Received”.

 Rename the column to Date Received

To simplify this table and filter out unnecessary columns for our analysis, we can remove all columns in the table except for the “Subject” and “Date Received” columns, and change the Load Settings at the bottom of the Query Settings pane so we load the resulting data directly into the Data Model and not to the worksheet.

 Simplify the table

Now we can click “Apply and Close” and the query will start evaluating. This evaluation may take some time, as in my case it will download over 35,000 rows of Exchange mail data.

 Query will start evaluating

Creating a Power View report

Once the query has finished downloading, we can use Power View to build a line chart that displays the count of items per date.

 Use Power View to build a line chart 

It doesn’t come as a surprise, but we can see how the volume of my incoming emails per day during the last year decreased during the holidays, such as Christmas and New Year, or during some other periods when I took time off work.

Results are displayed 

Sharing this query with others

In addition to visualizing this report, I could also share the query with other users using the Power BI for Office 365 Preview. I can share the query with everyone in my organization, but given that I don’t want to include a preview of the query (which contains email subjects), I can disable the preview as part of my sharing settings.

Share the query using Power BI for Office 365 preview 

After sharing the query, it will be easily discoverable for other users in my organization via Online Search, and they will be able to run the same analysis using their own Exchange account credentials.

Others may now run the same analysis using their own Exchange account credentials

Additional resources: