Aggregate function required inside the call to cumulative_sum

Hello

I am using grafana to visualize data from my rain-sensor. As my rain sensor zeros at 0700 everyday I have to calculate values from 0000 - 2400. While I was able to calculate values for my daily bar chart

SELECT SUM(nnd) 
  FROM (
  SELECT NON_NEGATIVE_DIFFERENCE("value")
    AS nnd FROM "mm" 
    WHERE $timeFilter
  ) time(1d)

I got stuck when I want to generate a cumulative sum of those values over the selected period. The following query returns the error aggregate function required inside the call to cumulative_sum:

SELECT CUMULATIVE_SUM(nnd) 
FROM (
  SELECT SUM(nnd)
  FROM (
    SELECT NON_NEGATIVE_DIFFERENCE("value") 
    AS nnd FROM "mm"
    WHERE $timeFilter
  ) GROUP BY time(1d)
) GROUP BY time(1d)

Can anyone explain why this isn’t working (the errormessage does not make a whole lot of sense to me).

Thank you

PS: full story here

1 Like

CUMULATIVE_SUM does not support group by time(), not in that way.

the following should work:

SELECT 
	CUMULATIVE_SUM(SUM(nnd)) 
FROM (
	SELECT NON_NEGATIVE_DIFFERENCE("value") AS nnd FROM "mm"
	WHERE $timeFilter
) GROUP BY time(1d)
2 Likes

Perfect, works! Thanks a lot!