InfluxDB queries - Cumulative sum of /

Hi,
I’m trying to display the % difference of a stock on grafana.
Here’s the queries that return the daily % variation.

Values are parsed from a csv file by telegraf:
|timestamp|open|high|low|close|volume|
|2020-12-01|123.9|125.83|123.08|123.16|5099334|
|2020-11-30|124.1|125|123.09|123.52|5987991|
|2020-11-27|124.2|125.313|123.91|124.35|2091186|
|2020-11-25|122.93|124.33|122.11|124.2|4135894|

SELECT (close / open) - 1 AS "calculated_percentage" FROM "stock" WHERE $timeFilter tz('America/New_York')

This query is working for the daily % variation between open and close.
I would like to be able to aggregate with cumulative_sum to know the total variation between 2 selected date.

When I try to add cumulative_sum around the (close / open) that didn’t work.

Any idea?

R,
xk3tchuPx

Hello @xk3tchuPx,
you need to perform a nested subquery

something like

SELECT cumulative_sum("calculated_percentage") AS "cumul_sum" FROM (SELECT (close/open)....)```