Forum Discussion
anrm6
11 months agoNew Member
Faster mail load from Exchange
Hi everyone, I’m working with Power Query and using the Exchange.Contents connector to access my Outlook mailbox. The issue is that my mailbox has over 400,000 emails, and Power Query tries to load ...
- 11 months ago
You may want to look into querying your mail messages via Graph API.
Some caveats:
- I have not used this directly in a while, so just going off memory / quick research / testing with Graph Explorer sample tenant.
- Graph integration with PBI is quite limited. Last I checked, though, you could still connect to personal mail through simple http calls and using PBI oauth. See MS party line on this: https://learn.microsoft.com/en-us/power-query/connecting-to-graph
- For a more enterprise solution, you may want to look into the MS recommended route of Graph Data Connect through Data Factory
Connecting would look something like this:
Web.Contents( "https://graph.microsoft.com/v1.0", [ // can query me/mailFolders and nav via childFolders; eg me/mailFolders/<id>/childFolders/<id>/messages RelativePath = "me/mailFolders/inbox/messages", Headers = [ accept = "application/json" ], Query = [ #"$orderby" = "sentDateTime desc", // props list for select: https://learn.microsoft.com/en-us/graph/api/resources/message#properties #"$select" = "id,sentDateTime,from,subject,bodyPreview", // eg filter to this year; datetime format is ISO 8601 (eg 2025-01-01T00:00:00Z) #"$filter" = "sentDateTime ge 2025-01-01", #"$top" = "100" // I believe max is 1000 - adjust as needed for performance ] ] )Parse the response as JSON (Json.Document). You'll get a JSON record with fields:
- value: list of records to upack with Table.FromRecords
- @odataNextLink: if more records exist than specified in $top, this will give the REST url for next page of size $top
Royel
11 months agoSuper User
Hi anrm6 you can try this
Step 1: Create a Parameter StartDateParam
Value: 1/1/2025 12:00:00 AM
Step 2: Create a new blank query and pest this code
let
Source = Exchange.Contents("[email protected]"),
Mail = Source{[Name="Mail"]}[Data],
FilteredData = Table.SelectRows(Mail, each [DateTimeReceived] >=StartDateParam),
BufferedResult = Table.Buffer(FilteredData)
in
BufferedResultNote: You need to update your email address
I have tested, its filtering rows based on parameters value and overall loading is faster.
Find this helpful? ✔ Give a Kudo • Mark as Solution – help others too!