# 'Time shift' defaults to previous year - in legacy Metric lens

**URL:** <https://discuss.elastic.co/t/time-shift-defaults-to-previous-year-in-legacy-metric-lens/337273>\
**Category:** Kibana\
**Tags:** lens\
**Created:** [June 30, 2023, 6:39am UTC](https://discuss.elastic.co/t/time-shift-defaults-to-previous-year-in-legacy-metric-lens/337273 "2023-06-30T06:39:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Schennings](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreas_schennings/32/111200_2.png) [@Andreas\_Schennings](https://discuss.elastic.co/u/Andreas_Schennings)\
**Post date:** [June 30, 2023, 6:39am UTC](https://discuss.elastic.co/t/time-shift-defaults-to-previous-year-in-legacy-metric-lens/337273/1 "2023-06-30T06:39:44Z")

</div>

Hi!

I´ve created a Legacy Metric lens that should display the Trend (in percent CO2) compared to a baseyear of 2019. But it always defaults to display the trend compared to previous year.

I´ve created a small [video](https://carboncompute-my.sharepoint.com/:v:/p/andreas_schennings/EU8kW9mcYy9OiUfyf1Qlu4YBM97o1ECfeosTC_HvYjdSVQ?e=p6icnP) here about the error.

This is my code:  
\<  
(sum(co2tonnes) - sum(co2tonnes, shift='startAt(2018-12-31T23:00:00.000Z)'))  
/  
(sum(co2tonnes, shift='startAt(2018-12-31T23:00:00.000Z)'))  
/\>

When I edit the lens and changes the global time, it works perfectly and shows the correct numbers compared to 2019:  
2020 -69%  
2021 -89%  
2022 -98%

But when the lens is saved to the dashboard, it instead shows the numbers compared to prevoius year instead which is wrong:  
2020 - 69%  
2021 -64%  
2022 -78%

This seems to be a bug. Anyone knows what to do?

---

<div class="post-metadata">

**Author:** ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)\
**Post date:** [July 20, 2023, 1:11pm UTC](https://discuss.elastic.co/t/time-shift-defaults-to-previous-year-in-legacy-metric-lens/337273/2 "2023-07-20T13:11:42Z")

</div>

I think you hit a bug @Andreas_Schennings. Sorry for the inconvenience.

I could reproduce and opened an issue, feel free to subscribe or chime in with any additional feedback

> <https://github.com/elastic/kibana/issues/162326>
>
> Reported at this \[discuss thread\](https://discuss.elastic.co/t/time-shift-defaul…ts-to-previous-year-in-legacy-metric-lens/337273).
> 
> 
> \*\*Kibana version:\*\*
> Reproduced in \`main\`, \`8.8.1\`, and \`8.9.0-SNAPSHOT\`
> 
> \*\*Elasticsearch version:\*\*
> Same
> 
> \*\*Server OS version:\*\*
> Elastic Cloud for 8.8.1 and Ubuntu 22.04 for \`main\` and \`8.9.0-SNAPSHOT\`
> 
> \*\*Browser version:\*\*
> Firefox 115.0.2 (64-bit)
> 
> \*\*Browser OS version:\*\*
> Ubuntu 22.04
> 
> \*\*Original install method (e.g. download page, yum, from source, etc.):\*\*
> Elastic Cloud for 8.8.1, from sources for \`main\`, and Docker for \`8.9.0-SNAPSHOT\`
> 
> \*\*Describe the bug:\*\*
> Kibana global time range is not correctly applied to visualizations that include a time shift parameter.
> 
> \*\*Steps to reproduce:\*\*
> 
> Create the following index that adds two data points per year from 2019 to 2023, increasing 10 units per year.
> 
> \<details\>\<summary\>Data to reproduce\</summary\>
> 
> \`\`\`
> PUT discuss-337273
> {
> "mappings": {
> "properties": {
> "timestamp": {"type": "date"},
> "metric": {"type": "float"}
> }
> }
> }
> 
> POST discuss-337273/\_bulk
> { "index": {}}
> { "timestamp": "2019-07-20", "metric": 10 }
> { "index": {}}
> { "timestamp": "2019-07-20", "metric": 10 }
> { "index": {}}
> { "timestamp": "2020-07-20", "metric": 20 }
> { "index": {}}
> { "timestamp": "2020-07-20", "metric": 20 }
> { "index": {}}
> { "timestamp": "2021-07-20", "metric": 30 }
> { "index": {}}
> { "timestamp": "2021-07-20", "metric": 30 }
> { "index": {}}
> { "timestamp": "2022-07-20", "metric": 40 }
> { "index": {}}
> { "timestamp": "2022-07-20", "metric": 40 }
> { "index": {}}
> { "timestamp": "2023-07-20", "metric": 50 }
> { "index": {}}
> { "timestamp": "2023-07-20", "metric": 50 }
> \`\`\`
> \</details\>
> 
> Import the following Dashboard and Data view: \[export.zip\](https://github.com/elastic/kibana/files/12107932/export.zip)
> 
> Additionally you can also configure these customer ranges for the date picker:
> 
> \<details\>\<summary\>Custom time ranges\</summary\>
> 
> \`\`\`
> \[
> {
> "from": "2019-01-01",
> "to": "2020-01-10",
> "display": "2019"
> },
> {
> "from": "2020-01-01",
> "to": "2021-01-10",
> "display": "2020"
> },
> {
> "from": "2021-01-01",
> "to": "2022-01-10",
> "display": "2021"
> },
> {
> "from": "2022-01-01",
> "to": "2023-01-10",
> "display": "2022"
> },
> {
> "from": "2023-01-01",
> "to": "2024-01-10",
> "display": "2023"
> }
> \]
> \`\`\`
> \</details\>
> 
> It has three panels that present the elements of a fourth panel with a ratio.
> 
> !\[image\](https://github.com/elastic/kibana/assets/188264/c7f4ee78-98ef-4fd6-859a-3e3ec622a6f4)
> 
> The main panel on the right has all the elements of this "formula" as follows:
> 
> \`\`\`
> (average(metric) - average(metric, shift='startAt(2018-12-31T23:00:00.000Z)'))
> /
> (average(metric, shift='startAt(2018-12-31T23:00:00.000Z)'))
> \`\`\`
> 
> So when filtering 2023 (average 50), the ratio is a growth of 400%, when filtering 2022, it should be 300%, and so on.
> 
> This works well inside the Lens editor, but on the Dashboard is not working correctly.
> 
> \*\*Expected behavior:\*\*
> Correct results in Dashboard.
> 
> \*\*Screenshots (if relevant):\*\*
> 
> The user contributed a video \[here\](https://carboncompute-my.sharepoint.com/:v:/p/andreas\_schennings/EU8kW9mcYy9OiUfyf1Qlu4YBM97o1ECfeosTC\_HvYjdSVQ?e=p6icnP)
> 
> (for some reason, I can't upload my recordings to github now :disappointed: )
> 
> These are screenshots of the time range fetched from the browser for a request for 2021:
> 
> | In Lens | In Dashboard |
> | :--: | :--: |
> | !\[2023-07-20\_15-02\](https://github.com/elastic/kibana/assets/188264/d826aa2e-8c76-458a-b3a0-245099188bf5) | !\[2023-07-20\_15-03\](https://github.com/elastic/kibana/assets/188264/5f35cddf-057c-49ef-9933-25d75d074dae) |
> 
> \*\*Errors in browser console (if relevant):\*\*
> Nothing I could see.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 17, 2023, 1:11pm UTC](https://discuss.elastic.co/t/time-shift-defaults-to-previous-year-in-legacy-metric-lens/337273/3 "2023-08-17T13:11:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
