Oversampling problem with cumulative sum

Hello,

I would like to calculate power consumption over time using cumulative sum function. The data is coming with 1 second period. The problem is when I select wider timer range, the data get oversampled, the sum is calculated from fewer values and I get incorrect result.

Is there any way to fix this?

You can try this Solution to solve your problem
Step :1 Create a table and store power consumption data


CREATE TABLE power_consumption_data (
    ts TIMESTAMP NOT NULL,
    power_watts DOUBLE PRECISION NOT NULL
);

Step : 2 Insert Dummy Data
Step :3 Integrate data source with grafana

Step : 4 write a query for running total of power consumption

SELECT
  SUM(power_watts) AS total_power_watts
FROM power_consumption_data;

Final Result Look Like


Hello @jaroslavprochazka
Just checking in—did this solution resolve your issue, or are you still experiencing the same problem?

Hello @infofcc3
Thanks for your reply. I haven’t had much time to get into this yet but Grafana is throwing an exception when I try to create a table using your syntax:


I am using Grafana-Athena as a data source.

hello @jaroslavprochazka

the given solution based on postgres data souce
please confirm the data souce is Amazon-Anthena sample of screentshort that help to understand the issue

Hello @infofcc3

Please see the screenshots of my query. I use a transformation to calculate the actual power consumption by multiplication of current and voltage.