"Failed to resolve 'top' key column" Error in Application Insights Analytics Custom Dimensions

464 views Asked by At

I have some data in Application Insights, and I am using the Analytics view to write queries against it.

I can see that I have a trace, the CustomDimensions of which contain a property called ActivityID, which is a guid:

enter image description here

What I want to do is now run another query to return all traces that contain that ActivityId.

Using this as guide, I currently have the following:

union (traces
| extend ActivityId = tostring(customDimensions.ActivityId)
| project ActivityId
| where ActivityId  == "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
| top 101 by timestamp desc

However, this is returning the following syntax error message:

Failed to resolve 'top' key column

What am I doing wrong? I would also appreciate and an explanation of the error message if possible.

2

There are 2 answers

4
Peter Bons On BEST ANSWER

You cannot do a top on projection unless you actually include the timestamp column in the projection.

I did :

union (traces)
| top 101 by timestamp desc
| project session_Id

so this should work

union (traces
| extend ActivityId = tostring(customDimensions.ActivityId)
| where ActivityId  == "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
| top 101 by timestamp desc
| project ActivityId

and then it works. What is your complete query (I guess there is more since you are using union?)

0
yonisha On

You must project the 'timestamp' column if you want to use it inside the top.

traces
| extend ActivityId = tostring(customDimensions.ActivityId)
| project ActivityId, timestamp
| where ActivityId  == "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
| top 101 by timestamp desc

*Note that you also do not need to use union