Lets a query read a value from an earlier row of its own results, avoiding the need to join the table to itself. With IGNORE NULLS, NULLs are skipped over.
Read more: Microsoft Learn
In the Ultra Transcenders books
Each book explains LAG in context, with comparison tables and the common traps.
Terms in this definition
- CRUD
Shorthand for create, read, update and delete, the four basic things you do with data. Data-plane roles in Azure Cosmos DB, for instance, authorise those operations on items.
- EARLIER
Within nested DAX row contexts, lets an inner calculation read a column as it stood in an outer pass; EARLIEST jumps to the outermost. Most people now use variables, which read more clearly.
- JOIN
Combines rows from two or more tables in one SELECT, most often by pairing a primary key with the foreign key that refers to it.
- Event
Table in Log Analytics where entries from Windows event logs are kept.
- RESPECT NULLS
The default behaviour of LAG, LEAD, FIRST_VALUE and LAST_VALUE, in which NULLs are counted. Its opposite, IGNORE NULLS, skips them, which is handy for carrying the last known value forward.
- OVER
Gives a T-SQL window function its window: PARTITION BY, ORDER BY and, if wanted, a ROWS or RANGE frame. Rankings and running totals can then be worked out while every row is kept.
Related terms
- Metadata sync
Fabric watches the Delta logs under a lakehouse's /Tables folder and brings the SQL analytics endpoint up to date with them automatically, so a new or altered table becomes queryable there after a brief lag.
- NRT rule
Short for near-real-time rule. This Microsoft Sentinel analytics rule fires each minute, looking at one minute of ingested data with a two-minute lag; up to 50 can be enabled, and 100 can exist counting disabled rules.
- Window function
A function evaluated OVER a window defined by PARTITION BY, ORDER BY and optionally a frame; unlike GROUP BY aggregation it doesn't collapse rows, but adds to each one a value worked out from its related rows. Examples are RANK, ROW_NUMBER, LAG and running totals.