-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQuery-HandleDynamicSetOfColumns.txt
31 lines (31 loc) · 1.41 KB
/
Query-HandleDynamicSetOfColumns.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let AnalyticsQuery =
let Source = Json.Document(Web.Contents("https://api.applicationinsights.io/v1/apps/"&#"ApplicationInsightsId"&"/query",
[Query=[#"query"="customMetrics
| where operation_Id != """"
| project timestamp, name, value, appName, opName=operation_Name, customDimensions
| evaluate bag_unpack(customDimensions)
| order by timestamp desc
",#"x-ms-app"="AAPBI",#"timespan"=AzureDataTimespan,#"prefer"="ai.response-thinning=true"],Timeout=#duration(0,0,4,0)])),
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
Table,
#"Removed Columns" = Table.SelectColumns(AnalyticsQuery,{"timestamp", "name", "value", "appName", "opName", "prop__VnbLookupId", "prop__Subscription", "prop__VnbDefinitionId"},MissingField.UseNull)
in
#"Removed Columns"