nerdexam
Microsoft

DP-700 · Question #103

You have a KQL database that contains a table named Readings. You need to build a KQL query to compare the MeterReading value of each row to the previous row based on the Timestamp value. A sample…

This question tests knowledge of KQL row-context window functions used to compare values across adjacent rows in a serialized result set. The core skill is using prev() together with serialize and order by to access the previous row's value.

Design and implement data ingestion and transformation

Question

You have a KQL database that contains a table named Readings. You need to build a KQL query to compare the MeterReading value of each row to the previous row based on the Timestamp value. A sample of the expected output is shown in the following table. How should you complete the query? To answer, drag the appropriate values the correct targets. Each value may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.

Explanation

This question tests knowledge of KQL row-context window functions used to compare values across adjacent rows in a serialized result set. The core skill is using prev() together with serialize and order by to access the previous row's value.

Approach. The correct query pattern is: (1) order by Timestamp asc to sort rows chronologically, (2) serialize to lock the row order and enable row-context functions, (3) extend PreviousReading = prev(MeterReading, 1) to pull the MeterReading value from the immediately preceding row, and optionally (4) extend Difference = MeterReading - PreviousReading to compute the delta. Without serialize, KQL does not guarantee row order and prev()/next() will throw an error. The full pattern is: Readings | order by Timestamp asc | serialize | extend PreviousReading = prev(MeterReading, 1).

Concept tested. KQL row-context window functions: the serialize operator (required to enable ordered row access), the prev(column, offset) function (retrieves a value from N rows above in the serialized set), and the extend operator (adds computed columns). This is distinct from aggregation - no summarize is needed because you are comparing row-by-row, not grouping.

Reference. https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/prevfunction

Topics

#KQL#Data transformation#Window functions#Lag/Previous row

Community Discussion

No community discussion yet for this question.

Full DP-700 Practice