Skip to content

bigfunctions > last_value

last_value

Call or Deploy last_value ?

✅ You can call this last_value bigfunction directly from your Google Cloud Project (no install required).

  • This last_value function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework

Public BigFunctions Datasets:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

last_value(arr)

Description

Return last value of array (inspired from sql-snippets repo)

Examples

select bigfunctions.eu.last_value([1, 2, 3])
select bigfunctions.us.last_value([1, 2, 3])
select bigfunctions.europe_west1.last_value([1, 2, 3])
+-------+
| value |
+-------+
| 3     |
+-------+

Need help using last_value?

The community can help! Engage the conversation on Slack

For professional suppport, don't hesitate to chat with us.

Found a bug using last_value?

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

For professional suppport, don't hesitate to chat with us.

Use cases

Imagine you have a table of customer orders, and each order has an array of timestamps representing different stages of the order fulfillment process (e.g., order placed, payment processed, shipped, delivered). You want to find the last timestamp in each array, which would represent the time the order was completed (delivered in this example).

SELECT
    order_id,
    bigfunctions.us.last_value(fulfillment_timestamps) AS order_completion_timestamp
FROM
    your_project.your_dataset.your_order_table

This query would use the last_value function to extract the last timestamp from the fulfillment_timestamps array for each order, giving you the order completion time.

Other use cases could include:

  • Finding the latest status update: If you have an array of status updates for a task or project, last_value can give you the most recent status.
  • Getting the last element of a sequence: If you have an array representing a sequence of events, last_value can retrieve the final event in the sequence.
  • Extracting the latest value from sensor readings: If you have an array of sensor readings over time, last_value can retrieve the most recent reading.

Essentially, anytime you need to efficiently extract the last element from an array within BigQuery, the last_value function provides a clean and easy solution.

Spread the word

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on