# Using LAST_VALUE with STRUCTS


Even an “empty” STRUCT is still technically something. Not the same as a standalone NULL value.

This is why, if you work with STRUCTs in SQL and try to find the latest non-empty struct using LAST\_VALUE(...) IGNORE NULLS, you’ll notice it doesn’t help — because the struct, even when all fields are null, is still considered non-null.

LAST\_VALUE only skips rows where the entire expression itself is NULL.

To fix this, we can adjust the logic in one of the following ways:  
➡️ Setting the value to NULL when all fields are NULL  
➡️ Using TO\_JSON\_STRING + NULLIF to treat such entries as “null”  
➡️ Using REGEXP\_CONTAINS (thanks ChatGPT) for more dynamic checks

Alternatively, we can just apply LAST\_VALUE separately to each individual field in the struct.

If you're new to STRUCTs, see [one of my previous posts](https://datawise.dev/understanding-structs-in-bigquery).

![](https://miro.medium.com/v2/resize:fit:700/0*pIPD5kXi-zhsJzwD align="left")

*Found it useful? Check out to my Analytics newsletter at* [*notjustsql.com*](https://notjustsql.com)*.*

---

*Enjoyed this? Here are some related articles you might find useful:*

- [Beware of ROW_NUMBER without ORDER BY](https://datawise.dev/beware-of-rownumber-without-order-by)
- [Tidying up WINDOW functions in BigQuery with named windows](https://datawise.dev/tidying-up-window-functions-in-bigquery-with-named-windows)
- [Using RANGE in Window Functions in BigQuery](https://datawise.dev/using-range-in-window-functions-in-bigquery)
- [Computing a cumulative sum in BigQuery](https://datawise.dev/computing-a-cumulative-sum-in-bigquery)

