solipsicle
solipsicle

Reputation: 904

Getting total milliseconds of a timespan in Analytics Query Language

I'm trying to render the difference between two dates over time in Application Insights Analytics, but timespan isn't a supported type for the y-axis of a timechart.

Example query:

customMetrics
| extend dateDiff = timestamp - (timestamp - 1m) 
// my second date comes from customDimensions
| summarize max(dateDiff) by bin(timestamp, 10m)
| order by timestamp desc
| render timechart

I'd like to transform my dateDiff timespan into an integer representing the number of milliseconds but I can't find anything in their documentation that supports this. I basically want C#'s TimeSpan.TotalMilliseconds().

Upvotes: 3

Views: 7899

Answers (1)

ZakiMa
ZakiMa

Reputation: 6281

You can divide your timespan by another timespan. So, to get number of milliseconds you can do the following:

customMetrics
| extend dateDiff = timestamp - (timestamp - 1m)
// get total milliseconds 
| extend dateDiffMilliseconds = dateDiff / time(1ms)
// my second date comes from customDimensions
| summarize max(dateDiff) by bin(timestamp, 10m)
| order by timestamp desc
| render timechart

More about date and time expressions can be found here: https://learn.microsoft.com/en-us/azure/application-insights/app-insights-analytics-reference#date-and-time-expressions

Upvotes: 10

Related Questions