Search code examples
azure-application-insightsazure-monitor

Kusto / Azure Application Insights - How to compare data against same day of previous weeks?


Using Kusto (application insights, log analytics, azure monitor) how can I compare data from my current day (eg: Monday), against data from all previous similar days?

a.k.a, how to compare current monday to previous Mondays only?


Solution

  • requests
    | where timestamp > ago(90d)
    | where dayofweek(timestamp) == dayofweek(now())
    | summarize count() by bin(todatetime(strcat("20210101 ", format_datetime(timestamp,"HH:mm:ss"))),5m),tostring(week_of_year(timestamp))
    | render timechart
    

    The trick is to group the timestamp using the same date, keeping the time portion AND the week_of_year (which has to be casted to string otherwise it will be interpreted as another numeric value)