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.
Question
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
Community Discussion
No community discussion yet for this question.