# Use grafana to show a time series year to year comparison of temperature data

**URL:** <https://community.grafana.com/t/use-grafana-to-show-a-time-series-year-to-year-comparison-of-temperature-data/154904>\
**Category:** Time Series Panel\
**Created:** [July 21, 2025, 6:50pm UTC](https://community.grafana.com/t/use-grafana-to-show-a-time-series-year-to-year-comparison-of-temperature-data/154904 "2025-07-21T18:50:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![umbertones](https://avatars.discourse-cdn.com/v4/letter/u/858c86/32.png) [@umbertones](https://community.grafana.com/u/umbertones)\
**Post date:** [July 21, 2025, 6:50pm UTC](https://community.grafana.com/t/use-grafana-to-show-a-time-series-year-to-year-comparison-of-temperature-data/154904/1 "2025-07-21T18:50:41Z")

</div>

- What Grafana version and what operating system are you using?  
Linux with Grafana 12.0.2

- **What** are you trying to achieve?  
I want a time series panel where I get to curves of my temperature data that are one year apart. At best it uses the interval that is set on top of the panel.

- **How** are you trying to achieve it?  
I tried several queries I found on the internet but none of them was able to shift the second curve so that it was shown in the panel  
I tried Grot AI, but his instructions were to vague for my experience level

Since I consider my query not so extraordinary I wonder why there is no “time shift” option for curve in the time series panel. Am I missing some of the underlying concepts?

---

<div class="post-metadata">

**Author:** ![infofcc3](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/infofcc3/32/51248_2.png) [@infofcc3](https://community.grafana.com/u/infofcc3)\
**Post date:** [July 22, 2025, 9:11am UTC](https://community.grafana.com/t/use-grafana-to-show-a-time-series-year-to-year-comparison-of-temperature-data/154904/2 "2025-07-22T09:11:48Z")

</div>

you can try this solution to resolve your Issue  
Step: 1 Step up your data source and insert demo data for 2-3 year  
a. Create table Like

```auto

CREATE TABLE temperature_readings (
    timestamp timestamptz NOT NULL,
    temperature numeric NOT NULL
);

```

b. Insert dummy data

```auto

INSERT INTO temperature_readings (timestamp, temperature)
VALUES
-- 20 data points for present year
(now() - interval '19 days', 15.2),
(now() - interval '18 days', 16.8),
(now() - interval '17 days', 14.7),
(now() - interval '16 days', 12.3),
(now() - interval '2 years' - interval '4 days', 5.6),
(now() - interval '2 years' - interval '3 days', 4.9),
(now() - interval '2 years' - interval '2 days', 4.2),
(now() - interval '2 years' - interval '1 day', 3.7),
(now() - interval '2 years', 3.1);
(now() - interval '2 years' - interval '9 days', 10.7),
(now() - interval '2 years' - interval '8 days', 9.4),
(now() - interval '2 years' - interval '7 days', 8.2),
(now() - interval '2 years' - interval '6 days', 7.9),
(now() - interval '2 years' - interval '5 days', 6.8),

```

Step: 2 Integrate Postgresql Data Souce in Grafana  
Step : 3 execute the query for calculate the sum year wise

```auto

SELECT
EXTRACT(YEAR FROM timestamp) AS year,
SUM(temperature) AS total_value
FROM temperature_readings
GROUP BY year
ORDER BY year;

```

Step 4 and finaly you compare the data year Wise  
Step :5 Select you visualization Like XY Chart

Final Output

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/1/5/15a35e73ee9fb5b1857cf7a2f9dbfaf9efc791aa.png)

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/f/b/fbad8088a260c96f6575ae5e74ca41e62d1af047.png)

---

<div class="post-metadata">

**Author:** ![umbertones](https://avatars.discourse-cdn.com/v4/letter/u/858c86/32.png) [@umbertones](https://community.grafana.com/u/umbertones)\
**Post date:** [July 26, 2025, 3:24pm UTC](https://community.grafana.com/t/use-grafana-to-show-a-time-series-year-to-year-comparison-of-temperature-data/154904/3 "2025-07-26T15:24:47Z")

</div>

Thanks for the explanation.

But I’m afraid, I can’t follow you.

I have time series data in an InfluxDB.

I want two graphs of Temperature.

One with the actual values for the interval selected in the graph  
And a second with the same datasource and sensor value but time shifted 1 year back (or 2 or …)

The most easy thing to do that would be an option in the query that says time shift.

Sure it is not as easy as it sounds as you might not find data points that are exactly one year away but with a little fuzziness allowed this should be possible.

I found a time shift field in the documentation. But I don’t find it in my installation.

EDIT: never mind, I’m blind…

But: this shifts the whole panel. I would like to have an individual time shift for Query B

---

<div class="post-metadata">

**Author:** ![umbertones](https://avatars.discourse-cdn.com/v4/letter/u/858c86/32.png) [@umbertones](https://community.grafana.com/u/umbertones)\
**Post date:** [November 24, 2025, 9:06pm UTC](https://community.grafana.com/t/use-grafana-to-show-a-time-series-year-to-year-comparison-of-temperature-data/154904/4 "2025-11-24T21:06:24Z")

</div>

I finally solved it with help from Gemini.

Had to create a new data source with Flux as the query language and created a time series dashboard with these two queries

A (now)  
from(bucket: “myweatherbucket”)

|\> range(start: v.timeRangeStart, stop: v.timeRangeStop)

|\> filter(fn: (r) =\> r[“\_measurement”] == “Klimadaten”)

|\> filter(fn: (r) =\> r[“Ort”] == “Aussen”)

|\> filter(fn: (r) =\> r[“\_field”] == “Temperatur”)

|\> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)

|\> yield(name: “Dieses Jahr”) // Legende

B: (one year backshift)  
import “experimental”

from(bucket: “myweatherbucket”)

// 1. Hole den Zeitraum VOM VORJAHR, basierend auf dem Dashboard-Bereich

|\> range(

```
start: experimental.subDuration(d: 1y, from: v.timeRangeStart),

stop: experimental.subDuration(d: 1y, from: v.timeRangeStop)

```

)

|\> filter(fn: (r) =\> r[“\_measurement”] == “Klimadaten”)

|\> filter(fn: (r) =\> r[“Ort”] == “Aussen”)

|\> filter(fn: (r) =\> r[“\_field”] == “Temperatur”)

|\> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)

// 2. Schiebe die Zeitstempel der Ergebnisse um 1 Jahr nach vorne

|\> timeShift(duration: 1y)

|\> yield(name: “Vorjahr”) // Legende

Never ever would I have figured that out myself….
