Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Write KQL queries to analyze logs and metrics

A worked example

Single answer

A developer runs the query in the exhibit against an Application Insights resource. The query returns thousands of rows because each distinct timestamp forms its own group. The developer needs daily counts of failed requests for the same rolling seven-day window, with one row for each daily bucket that contains request telemetry.

requests
| where timestamp > ago(7d)
| summarize failedCount = countif(success == false) by timestamp

Which change should the developer make to the query?

Choose one answer
Why

Grouping by the raw timestamp column creates one group per unique timestamp. Using bin(timestamp, 1d) instead combines requests into daily buckets and returns one row for each bucket represented in the filtered data. Limiting the row count with take or top, or narrowing the window, does not change how the rows are grouped.

  • Not correct: Append | take 7 to the end of the query. take returns an arbitrary set of rows. Each row still holds the count for a single timestamp, not for a day.
  • Not correct: Append | top 7 by failedCount desc to the end of the query. top returns the highest-valued rows. Each row is still grouped by a single timestamp, not by day.
  • Correct: Replace by timestamp with by bin(timestamp, 1d). bin(timestamp, 1d) rounds timestamps down to daily boundaries, combining requests into one group per daily bucket represented in the filtered data.
  • Not correct: Replace ago(7d) with ago(1d) in the where clause. This shortens the time window to one day and leaves the grouping unchanged, so it does not produce daily counts for the required window.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free