Integrate Log Analytics and Excel

You can integrate Azure Monitor Log Analytics and Microsoft Excel using M query and the Log Analytics API. This integration allows you to send up a certain number of records and MB of data. These limits are documented in the Azure Monitor Log Analytics workspace limits in the Azure portal section.


Because Excel is a local client application, local hardware and software limitations impact it's performance and ability to process large sets of data.


To integrate Log Analytics and Excel, you need:

Permissions required

You must have Microsoft.OperationalInsights/workspaces/query/*/read permissions to the Log Analytics workspaces you query, as provided by the Log Analytics Reader built-in role, for example.

Create your M query in Log Analytics

  1. Create and run your query in Log analytics as you normally would. Don’t worry if you hit the number of records limitation in the user interface. We recommend you use relative dates - like the ‘ago’ function or the UI time picker - so Excel refreshes the right set of data.

  2. Export Query - Once you are happy with the query and its results, export the query to M using Log Analytics Export to Power BI (M query) menu choice under the Export menu:

    Screenshot of Log Analytics query with the data and export option.

Choosing this option downloads a .txt file containing the M code you can use in Excel.

The query shown above exports the following M code. Here’s an example of the M code exported for the query in our example:

The exported Power Query Formula Language (M Language ) can be used with Power Query in Excel
and Power BI Desktop.
For Power BI Desktop follow the instructions below: 
1) Download Power BI Desktop from
2) In Power BI Desktop select: 'Get Data' -> 'Blank Query'->'Advanced Query Editor'
3) Paste the M Language script into the Advanced Query Editor and select 'Done'

let AnalyticsQuery =
let Source = Json.Document(Web.Contents("", 

| summarize dcount(ComputerIP) by bin(TimeGenerated, 1h)    
| render timechart
TypeMap = #table(
{ "AnalyticsTypes", "Type" }, 
{ "string",   Text.Type },
{ "int",      Int32.Type },
{ "long",     Int64.Type },
{ "real",     Double.Type },
{ "timespan", Duration.Type },
{ "datetime", DateTimeZone.Type },
{ "bool",     Logical.Type },
{ "guid",     Text.Type },
{ "dynamic",  Text.Type }
DataTable = Source[tables]{0},
Columns = Table.FromRecords(DataTable[columns]),
ColumnsWithType = Table.Join(Columns, {"type"}, TypeMap , {"AnalyticsTypes"}),
Rows = Table.FromRows(DataTable[rows], Columns[name]), 
Table = Table.TransformColumnTypes(Rows, Table.ToList(ColumnsWithType, (c) => { c{0}, c{3}}))
in AnalyticsQuery

Connect Query to Excel

To import the query.

  1. Open Microsoft Excel.

  2. In the ribbon, go to the Data menu. Select get data. From other sources, select blank query:

    Import from blank in Excel option

  3. In the Power query window select Advanced editor:

    Excel Advanced query editor

  4. Replace the text in the advanced editor with the query exported from Log Analytics:

    Creating a blank query

  5. Select Done, and then Load and close. Excel executes the query using the Log analytics API and the result set then shown.

    Query results in Excel


If the number of records is less than expected, the volume of the results might exceeded the 61MiB limit. Try using project or project-away in your query to limit the columns to the one you need.

Refreshing data

You can refresh your data directly from Excel. In the Data menu group in the Excel ribbon, select the Refresh button.

Next steps

For more information about Excel’s integrations with external data sources, see Import data from external data sources (Power Query)