func.last_value

The LAST_VALUE() function is a window function that returns the last value in an ordered partition of a result set

Syntax

func.last_value(field).over(partition_by=field, order_by=field)

Examples

This is an example of using the last_value() capability to calculate the time remaining in time series data where each event is on a distinct row.

This assumes you have a table of time series data that looks like this:

locationemployeetimestamp
Building AJohn Doe2022-01-05 15:34:31
Building AJohn Doe2022-01-05 15:44:31
Building AJohn Doe2022-01-05 15:46:41
func.last_value(table.timestamp, 1).over(partition_by=[table.location, table.employee], order_by=table.timestamp) - table.timestamp

Adding the expression above to an Interval column called remaining would result in an output table like this:

locationemployeetimestampremaining
Building AJohn Doe2022-01-05 15:34:3100:12:10
Building AJohn Doe2022-01-05 15:44:3100:02:10
Building AJohn Doe2022-01-05 15:46:4100:00:00
Last modified April 06, 2022 at 10:08 AM EST: Initial Documentation Commit (371ae8f)