Grafana Open search - RSI calculation(Relative strength index)

I am using Open search to calculate RSI. For that I need to do average Gain/loss kind of calculation. This will need to subtract value from previous value of a metric. Can I do this using TRANSFORMATION?

There is a transformation called Difference- difference between 1st & last value. What does this actually mean?

Reference for RSI calculation- Relative Strength Index (RSI) [ChartSchool]

can you share your raw, unformatted data and the necessary calculations needed to achieve your desired result?