Last value in painless script

Hello Team,

Like in the title, I am trying to get the last_value of a field for the Return On Investment calculation. Normally, I can do this in Lens Formula (rf. below) on a monthly index. But I don't know how for a daily index.

ROI = sum(*sessions*) / last_value(*subscription_fee*)

So the idea is to get the last subscription_fee, I've been trying to play around with @timestamp field but no hope.

How could I tackle that ?
Thanks in advance,

Hi @martinsbleu !

A couple of questions:

  1. the ROI formula is (current value - initial value) / initial value. Can you clarify how your data are supposed to fit that formula?

  2. when you say

do you mean that each document in the index represents the value of the investment on a particular day?

Hello @Andrew_Tate !
Thanks you for reply!!

  1. Yes, pardon me, current value would the total number of sessions (sessions field).
  2. A daily index is an index with data populated each day. So I think it is close to what you have described (:

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