Advertisement
mobilefish

Untitled

Mar 10th, 2021
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. /*
  2. The exported Power Query Formula Language (M Language ) can be used with Power Query in Excel
  3. and Power BI Desktop.
  4. For Power BI Desktop follow the instructions below:
  5. 1) Download Power BI Desktop from https://powerbi.microsoft.com/desktop/
  6. 2) In Power BI Desktop select: 'Get Data' -> 'Blank Query'->'Advanced Query Editor'
  7. 3) Paste the M Language script into the Advanced Query Editor and select 'Done'
  8. */
  9.  
  10.  
  11. let AnalyticsQuery =
  12. let Source = Json.Document(Web.Contents("https://api.loganalytics.io/v1/workspaces/xxxxxxxxxxxxxx/query",
  13. [Query=[#"query"="
  14.  
  15.  
  16. AppRequests
  17. | summarize totalCount=sum(ItemCount) by bin(TimeGenerated, 30m), _ResourceId
  18. | render timechart
  19. ",#"x-ms-app"="OmsAnalyticsPBI",#"timespan"="P7D",#"prefer"="ai.response-thinning=true"],Timeout=#duration(0,0,4,0)])),
  20. TypeMap = #table(
  21. { "AnalyticsTypes", "Type" },
  22. {
  23. { "string", Text.Type },
  24. { "int", Int32.Type },
  25. { "long", Int64.Type },
  26. { "real", Double.Type },
  27. { "timespan", Duration.Type },
  28. { "datetime", DateTimeZone.Type },
  29. { "bool", Logical.Type },
  30. { "guid", Text.Type },
  31. { "dynamic", Text.Type }
  32. }),
  33. DataTable = Source[tables]{0},
  34. Columns = Table.FromRecords(DataTable[columns]),
  35. ColumnsWithType = Table.Join(Columns, {"type"}, TypeMap , {"AnalyticsTypes"}),
  36. Rows = Table.FromRows(DataTable[rows], Columns[name]),
  37. Table = Table.TransformColumnTypes(Rows, Table.ToList(ColumnsWithType, (c) => { c{0}, c{3}}))
  38. in
  39. Table
  40. in AnalyticsQuery
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement