DIFFERENCE between first and last sample in a query?

I have a field that always increases and represents energy produced since startup. I want to be able to query for the amount of energy produced in a time window. This is just the difference between first and last samples. The DIFFERENCE() transformation gives me the difference between each subsequent point.

Alternatively, i am trying to get a graph that picks its zero as the first point and everything should be offset from there. I have tried:
SELECT energy-FIRST(energy) FROM "data"
But that gives me:
[panic:runtime error: invalid memory address or nil pointer dereference]

I’m running: 1.4.2