Query for second last item

Is it possible to construct a data query for the 2nd last item for a given variable?
device.getData({variable: 'blah', query: 'last_item'}) will get me the last item, but when triggering an analysis from a newly received data point, I just get the same item as the one coming through in the scope. I need the item before this one.

Help?

Hi, @sevils,
the getData will return a list of data ordered by the field time. So you can retrieve the last 2 items from the bucket using the qty key and then get data from position 1.

device
  .getData({ variable: "blah", qty: 2 })
  .then((data) => console.log(data[1]));

Thanks @stoklosa, i’ll check it out!