35

How can I summarize records by year, month,day and hour only?

Leonardo
  • 10,737
  • 10
  • 62
  • 155
  • 2
    Are you using [Application Insights Analytics](https://learn.microsoft.com/en-us/azure/application-insights/app-insights-analytics)? If so, try [datepart](https://learn.microsoft.com/en-us/azure/application-insights/app-insights-analytics-reference#datepart) – Peter Bons Jun 06 '17 at 13:37

1 Answers1

88

In Application Insights Analytics:

By hour:

requests 
 | summarize count() by bin(timestamp, 1h) 

By day:

requests 
 | summarize count() by bin(timestamp, 1d) 

By month

requests 
  | summarize count()  by bin(datepart("Month", timestamp), 1) 

By year

requests 
  | summarize count()  by bin(datepart("Year", timestamp), 1) 
Jeremy Hutchinson
  • 1,975
  • 16
  • 26
  • 10
    Just wanted to mention that there are also aliases for this: startofday(timestamp), startofweek, startofmonth and startofyear. it should be a bit easier to use. – Asaf Strassberg Jun 07 '17 at 09:15