Reference to the last() function


last([<timeWindow>,] <expression>)

Fills in gaps in the expression with the last known value of the expression. If you specify `a time window, fills in a specified time period after each existing point.


timeWindow By default, the last() function applies the specified value to gaps of missing data for up to 4 weeks. Use this optional parameter if you’d like this window to be smaller. The smallest time window you can specify is 1 second (1s).
expression Expression in which you want to replace gaps in data with the last value.


The last() function allows you to assign the last known reported data point value to a gap of missing data. When you add last() to a ts() expression, a solid straight line with the value of the last reported data point will be drawn in place of gaps of missing data.

By default, last() applies the last reported data value to gaps of missing data for up to 4 weeks. If you’d like this window to be smaller, you can use the timeWindow parameter. If you use last() with a function that uses interpolation, we apply last() to the last 15% of a chart window.


In the following example, we’ve zoomed in on ~sample.request.failures.num and see missing data.

ts_last before

We decide to replace the missing data with the last value before the gap, in this case 0.


Then we replace the missing data with the first good value after the gap using next.

ts next

See Also

Using Moving and Tumbling Windows to Highlight trends

Other missing data functions include default, next, and interpolate.