How do i make the "mean" calculation be respective of the time window?

Grafana version: Grafana Cloud

Hi there,

Im trying to understand how the “mean” calculation in various panels work. It seems as though it works off the entire data source / query, and doesn’t respect the time window filter.

In other words, if i setup a “Stat Panel”, and choose some data, maknig the calculation baed on “Mean”, it shows the mean of the entire window. WHen i change the filters, the mean doesn’t change, but the graph / data does. I expected the Mean to also change.

Can someone advise how i can make this happen? Do i need to have a seperate query?

Welcome @ryanmiranda

What is your data source and please share the query you are using

Hi @yosiasz sorry, i should have mentioned that :slight_smile:

It’s Microsoft SQL Server data source.

Here’s my query:

SELECT 
  Timestamp AS "time", 
  b.Name AS App,
  ErrorPercentage
FROM Metrics.dbo.Errors a
INNER JOIN Metrics.dbo.Apps b ON a.AppId = b.AppId
ORDER BY Timestamp ASC
1 Like

Got my answer. Needed to make use of macros.

So here is my updated query:

SELECT 
  Timestamp AS "time", 
  b.Name AS App,
  ErrorPercentage
FROM
  Metrics.dbo.Errors a
INNER JOIN
  Metrics.dbo.Apps b ON a.AppId = b.AppId
WHERE
  $__timeFilter(Timestamp)
ORDER BY
  Timestamp ASC