Azure Log analytics to query based on dates

1.9k Views Asked by At

I want to query a table in log analytics , to fetch count of records in last hour for today's date and to compare the count that fetched on same hour on the previous week (7 days before) on the same day.

I am not sure that below query helps me. Please help me in this.

Table1 | where TimeGenerated > now(-1h) and responseCode_d == 200 | summarize recount=count(responseCode) by responseCode | project responseCode,recount | join kind=inner ( Table1 | where TimeGenerated > now(-7d) and responseCode_d == 200 | summarize recount1=count(responseCode) by responseCode | project responseCode_d,recount1 ) on responseCode

1

There are 1 best solutions below

0
On

How about something like this?

Table1
| where TimeGenerated >= ago(1h) and TimeGenerated < now()
| where responseCode_d == 200
| summarize responseCountLastWeek=count() by responseCode
| project responseCode, responseCountLastWeek
| join kind=fullouter (
    Table1
    | where TimeGenerated >= ago(1h) - 7d and TimeGenerated < now() - 7d
    | responseCode_d == 200
    | summarize responseCountThisWeek=count() by responseCode
    | project responseCode, responseCountThisWeek
) on responseCode
| project
    responseCode = coalesce(responseCode, responseCode1),
    responseCountPrevWeek = coalesce(responseCountPrevWeek, 0),
    responseCountThisWeek = coalesce(responseCountThisWeek, 0)