Calculation power consumption

  • What Grafana version and what operating system are you using?

  • What are you trying to achieve? I have a electric power meter, i can read data as electric consumption data

  • How are you trying to achieve it? My question is: how to write the sql code to calculation the electric consumption in one day and sum up to week, month (for example: today it is 234kwh and next day is 500kwh then total consumption = 500-234 = 266kwh/day and continue…)

  • What happened?

  • What did you expect to happen?

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?

Hey @phungnguyennghiangoc, welcome to the community.

Sorry to say but your question isn’t really a Grafana question. It would be better if you look for some docs and examples on a SQL forum specifically about your database of choice.

Just to give you some pointers: your query seems like a classic “extract date_part, sum column, maybe where something, group by extracted_date_part” case, so try to work with the logic bellow:

SELECT extract_date_part(date_column, 'month') as "time",
    sum(my_column_to_be_summed) as "value",
    my_metric_column as "metric" 
FROM my_table

The code above will not work as in a copy/paste solution. You’ll need to search the right functions of your DBMS and change the columns for your case to make it work.

I wish you good studies.

It is grafana question: i means that i have a electric power meter connected to network and use opc server and sql to put in database as data source with table with 2 column: value (read from power meter) and other column as date.created.
After that using grafana to show this data a number, so my question as i need to help as previous question.
I think that you are clear for my problem. I remember i did read this topic in some where in grafana