Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I have a problem connecting Power BI to application insights. I will often get (502): Bad Gateway when running the query, and if I adjust the time period downwards in the query, it will then work.
I created the query in https://analytics.applicationinsights.io and chose the Export Power BI Query (M) option, then pasted that into Power BI Desktop.
The query is as follows:
let AnalyticsQuery =
let Source = Json.Document(Web.Contents("https://management.azure.com/subscriptions/0cd37710-98b7-4c41-ac4d-19a7f1f6cc0c/resourcegroups/JiwaFinancials/providers/microsoft.insights/components/jiwa7/api/query?api-version=2014-12-01-preview",
[Query=[#"csl"="pageViews | project ['timestamp'] = (timestamp + 10h + 0min), ['Form Name'] = name, ['Jiwa Version'] = customDimensions.[""Jiwa Version""],['Jiwa Username'] = customDimensions.[""Jiwa Username""],['Company Name'] = customDimensions.[""Company Name""],['Database Name'] = customDimensions.[""Database Name""],['SQL Product Version'] = customDimensions.[""SQL Product Version""],['SQL Product Edition'] = customDimensions.[""SQL Product Edition""],['SQL Product Level'] = customDimensions.[""SQL Product Level""],['Operating System'] = client_OS,['Country'] = client_CountryOrRegion,['State'] = client_StateOrProvince,['City'] = client_City",#"x-ms-app"="AAPBI", #"timespan"="P6D"],Timeout=#duration(0,0,16,0)])),
TypeMap = #table(
{ "DataType", "Type" },
{
{ "Double", Double.Type },
{ "Int64", Int64.Type },
{ "Int32", Int32.Type },
{ "Int16", Int16.Type },
{ "UInt64", Number.Type },
{ "UInt32", Number.Type },
{ "UInt16", Number.Type },
{ "Byte", Byte.Type },
{ "Single", Single.Type },
{ "Decimal", Decimal.Type },
{ "TimeSpan", Duration.Type },
{ "DateTime", DateTimeZone.Type },
{ "String", Text.Type },
{ "Boolean", Logical.Type },
{ "SByte", Logical.Type }
}),
DataTable = Source[Tables]{0},
Columns = Table.FromRecords(DataTable[Columns]),
ColumnsWithType = Table.Join(Columns, {"DataType"}, TypeMap , {"DataType"}),
Rows = Table.FromRows(DataTable[Rows], Columns[ColumnName]),
Table = Table.TransformColumnTypes(Rows, Table.ToList(ColumnsWithType, (c) => {c{0}, c{3}}))
in
Table
in
AnalyticsQuery
The part that determines the timespan : #"timespan"="P6D" seems to be related to the problem. If I change the timespan to P7D It fails with (502): Bad Gateway.
I thought maybe the timeout value was too small - but it's at 16 minutes and even when I increase the value the 502 error comes back within 2 to 3 seconds.
I tested retrieving the data from application insights using https://dev.applicationinsights.io/apiexplorer and I was able to retrieve 90 days worth of data without issue.
Why is Power BI giving me a Bad Gateway error when trying to retrieve more than 6 days of data?
Solved! Go to Solution.
Hi @mikesheen,
Based on my research, the bad gateway error is usually caused by that your query returns too much data. The gateway is limited to 8MB of data, period.
You can limit the time range by setting timespan to fix this issue, there is a similar thread for your reference.
Thanks,
Lydia Zhang
Hi @mikesheen,
Based on my research, the bad gateway error is usually caused by that your query returns too much data. The gateway is limited to 8MB of data, period.
You can limit the time range by setting timespan to fix this issue, there is a similar thread for your reference.
Thanks,
Lydia Zhang
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!