How to get a Moving Average with mysql datasource

Is it possible to create a moving average with mysql datasource?
I’ve a moving average working with influx, but it does not seem possible in the sample way.

I use grafana 7.4.0.

In case a moving average is possible with a mysql datasource, how should it be done?

Thanks in advance.

1 Like

@radoeka did you find a solution? I’m interested as well

No solution. Still waiting …

I know there are a few methods for achieving this published elsewhere online (if you google “MySQL moving average”). Out of curiosity, do none of them work for you?

@svetb that results in some usable descriptions at first glance, thanks. Need to have a look at those in more details in the coming days/time.

However, for the influxdb data source, the X days moving average can just be selected. Very convenient and nice. It would be nice if the mariadb datasource would be provide the same (if possible).

This article What a Moving Average Is and How to Compute it in SQL | describes it well, and it works well in Grafana too :slight_smile:

Thanks @svetb


Great that you worked it out, and thanks for the link! Sorry I wasn’t actually much help haha. And indeed, most SQL databases will generally not be quite as good at this type of stuff “out of the box” as a dedicated time series DB like Influx.

1 Like

@svetb you’re hint was the needed push!

But, it would be nice if Grafana would add an option that creates (inserts) the necessary code ( avg (<name>) OVER( ORDER BY <date>`` ROWS BETWEEN <MA Period> PRECEDING AND CURRENT ROW )

In this <name>, <date> and <MA Period> are to be populated by Grafana. Looks doable to me.