Lens Formula subtract first and last document

I want to subtract the last and the first document from a timerange to check how much engergy was consumed. So i make a lens with a formula like this :
(last_value(value.value_float32) - min(value.value_float32)) . I take the min value because it seems there is no function for the "first" document. The syntax works, but only for ca. 11 hours.


After that, the result of the min document is zero. so the visualtion will shw the "last" document. I checked the documents after 11 hours and there is no one document with a zero.

I also checked with other documents. Same result... So I don't get it, where my mistake is, or is it a bug? Maybe there is a another solution?

Greetz Thomas

Edit: I m working withe the Version 8.6.1

Hi @deepack86

welcome to the Kibana community.
In Kibana 8.7 the "previous" shift feature has been introduced which will allow you to perform a difference between the last value of the current time window and the previous one:

last_value(value.value_float32, kql='value.value_float32: *') - last_value(value.value_float32, kql='value.value_float32: *', shift='previous')

Hi Marco_Liberati,

thanks for your anwser! It works ver well... : )

Greetz Thomas

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.