Difference between two singlestat values?

I’m trying to work out how to subtract one singlestat value from another, to display the difference as a third value.

What I’m aiming for is a way to show 6 different singlestat values, each one showing the sum of a measurement for “yesterday”, “the day before yesterday”, “the day before that” and so on.

I’ve figured out that I can use Grafana’s “Time range” tab in the query builder to get the sum for yesterday with an “override” of “now/d” and a “time shift” of “1d”. I can’t figure out how to get the day before yesterday, but I can get both added together with an “override” of “now/d” and a “time shift” of “2d”, so if I can subtract the first calculated value from the second one, that will give me the answer I want, for the day before yesterday.

And so on.

I’ve tried an “override” of “now-1d/d” and “now/d-1d” but these get deleted and reset to empty.

I’m using InfluxDB as the data source, so I know that I can’t do any maths operations such as % (remainder) on time values, so I don’t think there’s any way of getting “the start of yesterday” and “the end of yesterday” into a query statement…

Does anyone have any ideas or solutions to this problem?

Thanks,

Antony.

if i understam to you:

When relative time time shift
Today now/d
yesterday now-1h/h 1d/d
the day before yesterday now-1h/h 2d/d
the day before that now-1h/h 3d/d

:grinning:

1 Like

Thanks for the comment, but I don’t understand what you’re suggesting I should
put into my Grafana query in order to get the value for “the day before
yesterday”.

Regards,

Antony.

What if you better explain your use case, and in this way I verify what I said

In fact I just figured it out, and wow is this obscure!

To show the value for “today so far” you use “override relative time” =
“now/d” and leave “add time shift” blank. So far so good.

To show the value for “yesterday” (midnight to midnight) you use “override
relative time” = “now/d” and set “add time shift” to “1d/d”.

For “the day before yesterday” you use “override relative time” = “now/d” and
set add time shift" to “2d/d”, and so on.

I had tried setting the time shift to “1d”, “2d” etc, but it hadn’t for a
moment occurred to me that the syntax might be “2d/d”. I’ve never seen
anything quite like that in another language, and whereas I’m pretty sure that
https://grafana.com/docs/reference/timerange/ is the right place in the
documentation to look for this stuff, it doesn’t say anything about this
syntax.

Incidentally, I got the clue about how to do this from

If anyone who actually knows how this syntax works (I mean, “1w/d” seems to do
something, and so does “1d/w”, but I have no idea what the background meaning
of those might be) could update the documentation to explain it, I think it
might enable a lot more people to use this very useful (in certain situations)
feature.

Antony.

Sorry if i was not clear, im glad that you understan

I’m planning to create a PR with examples some example to docs

Thanks very much Daniel… you saved my life with that regarding to relative times on panel queries… Grafana Docs definately suck!!!