How to show the difference between 2 selects as a stat control

Hi, for a dashboard I want to show how much energy I have consumed this year as a stat control. Data is stored inside Influx 1.8.

With A=SELECT last(“value”) FROM “stromzaehler” WHERE (“type” = ‘energy’) AND $timeFilter GROUP BY time($__interval) fill(null) I am getting the current vaue of my energy meter.

With B=SELECT first(value) FROM “stromzaehler_daily” WHERE time > ‘2023-01-01’ and “type” = ‘energy’ I am getting the value from january, 1st.

I want to show A-B as the difference.

Anyone that can help me on this?

Thanks and Regards,
Torsten

Hi @torsten67
Maybe this?

or this?

Thanks, the first version is almost what I am looking for, with the difference, that I don’t watn to display the value from jan,1st. I only want to display the value of today and the difference between today and jan. 1st.

Let’s try it another way without the transform, and instead create Expression C that is simply the difference between A and B. Then click the “eye” and hide Query A.

I did this quite similar to you, but for some reason the expression always shows no value. I can do $A-100 or $B-100, then I am getting a result, but $a-$B always does not return a result.

Hmmm…I looked through this and it mentions the Resample operation can line up the timestamps of the two series (if that is indeed what is causing no result to appear).

Ok, but how can I solve that problem?

How about doing two separate “Reduce” expressions (one for A and one for B), then do the math expression on C and D?

Great idea, that solved the problem! Thanks a lot!