Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
mikesheen
New Member

Connecting to Application Insights: Bad Gateway Error from Power BI

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?

 

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

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.

http://stackoverflow.com/questions/41869170/query-from-powerbi-to-ai-suddenly-fails-with-502-bad-gat...

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yuezhe-msft
Employee
Employee

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.

http://stackoverflow.com/questions/41869170/query-from-powerbi-to-ai-suddenly-fails-with-502-bad-gat...

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors