# Howto get max/min difference per hour from counter in flux?

I have a seemingly simple problem that I’ve been stuck on for hours. I have a counter and want to know by how much the counter increases per period and plot that in chronograf:

``````from(bucket: "volkszaehler")
|> range(start: dashboardTime)
|> filter(fn: (r) => r.title == "HcStarts")
|> filter(fn: (r) => r._field == "value")
|> aggregateWindow(every: 1d, fn: max)
|> derivative(unit: 1d, nonNegative: true, columns: ["_value"])
``````

Only I can’t use `max` since its not an aggregate function. Trying to use derivative first and the sum inside the aggreagteWindow didn’t work either.

How would I do this?

Answering myself here, I could probably do something like

`````` from(bucket: "volkszaehler")
|> range(start: dashboardTime, stop:upperDashboardTime)
|> filter(fn: (r) => r.title == "HcStarts")
|> aggregateWindow(every: 1d, fn: mean)
|> derivative(unit: 1d, nonNegative: true, columns: ["_value"])
``````

But that would at least shift the result by half a day (always assuming monotonic data), so its only an approximation using mean.

Do you have any further questions? It’s still a little unclear to me what your problem is.

Question answered- what I really wanted to do was use max() in aggregateWindow and I realize that should be possible with current flux- which is not yet available in Chronograf.

Thanks for getting back!

You meant the new flux is not yet available in chronograf?
There is a support for flux language in chronograf, below snippet is from chronograf version 1.7.3

No, I meant that flux 0.24 which is bundled with Cronograf 1.7.7 is too old to do this:

Why? Max is a selector, not an aggregate function. This is only supported with later versions of flux.