snowflake.snowpark.functions.lag¶
- snowflake.snowpark.functions.lag(e: ColumnOrName, offset: int = 1, default_value: ColumnOrLiteral | None = None, ignore_nulls: bool = False) Column [source]¶
Accesses data in a previous row in the same result set without having to join the table to itself.
Example:
>>> from snowflake.snowpark.window import Window >>> df = session.create_dataframe( ... [ ... [1, 2, 1], ... [1, 2, 3], ... [2, 1, 10], ... [2, 2, 1], ... [2, 2, 3], ... ], ... schema=["x", "y", "z"] ... ) >>> df.select(lag("Z").over(Window.partition_by(col("X")).order_by(col("Y"))).alias("result")).collect() [Row(RESULT=None), Row(RESULT=10), Row(RESULT=1), Row(RESULT=None), Row(RESULT=1)]