# One line per year with monthly buckets in line chart

**URL:** https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294
**Category:** Kibana
**Created:** [December 15, 2022, 11:08am UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294 "2022-12-15T11:08:42Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 11:08am UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/1 "2022-12-15T11:08:42Z")

</div>

Hello,

i have a line chart with a date histogram with monthly buckets on the horizontal axis. And a proportion of two cumulative sums on the vertical axis.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/7/f7aa367a719f534c2c7ae230eb67d8ba820c5d15.png)

Is there a way to overlay all years to have only a single year on the horizontal axis but then one line per year for the proportion. I don't know how to do it because of the cumulative sum requiring the date histogram.

Best regards  
Jonas

---

<div class="post-metadata">

### Author: ![dadiasish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadiasish/32/114221_2.png) [@dadiasish](https://discuss.elastic.co/u/dadiasish)
#### Post date: [December 15, 2022, 11:20am UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/2 "2022-12-15T11:20:28Z")

</div>

One simple way is to create two different Visualizations and add it together in a Dashboard side by side, if that works out for you.

---

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 11:40am UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/3 "2022-12-15T11:40:06Z")

</div>

Thanks, but i can't create 17 visualizations side by side. Also new data is coming in monthly so i would need to create another visualization every year.

I saw that with tsvb it is possible to offset a series. So i could create a series per year and offset each one by an additional year, but then i would have to create a new series every year from now on and i would like to avoid that.

I'm looking for a way to automatically split by year so from now on a new line is created every year and gets a new datapoint every month.

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [December 15, 2022, 11:47am UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/4 "2022-12-15T11:47:56Z")

</div>

Hi @Jonas_S

have you considered using the time\_shift option?  
Is still a manual job to create a new dimension per year, but way quicker than creating a panel per year.  
Here I have a formula function using `cumulative_sum` and I'm duplicating it replacing the `shift` option:

![cumulative_shift](https://us1.discourse-cdn.com/elastic/original/3X/0/c/0cc0dd2713c38bc8f7590614d2e6ccb131fdcdac.gif)

---

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 12:02pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/5 "2022-12-15T12:02:29Z")

</div>

Thanks for the suggestion. That sounds already pretty close to what i want.

But i'm not sure how to do it. If i add the shift to the two sums, no line is drawn:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/a/5a54ae45486e3083c8a40a40dce09eb8ef952e08.png)

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [December 15, 2022, 12:19pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/6 "2022-12-15T12:19:42Z")

</div>

I see there's a warning sign in there (yellow marks). I suspect you have to tweak a bit the date histogram interval in order to align the shift with it (the shift has to be a multiple of the interval): can you try to force the date\_histogram interval to `Month`?

---

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 12:38pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/7 "2022-12-15T12:38:07Z")

</div>

I think it already is Month, no? Is there another setting despite Minimum interval?  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/d/3d40794fb1f19055db37e1b38e34b8251778dce9.png)  
The warnings:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/1/d11b6a565bd2f677e39ee394b1cd71ad91d237cd.png)  
The warning persists even with 12M. It only goes away with 1M, but even then, no line is drawn:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/2/f23f59f78f7223df886e72ae0f9b960b92e0cf54.png)

---

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 1:20pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/8 "2022-12-15T13:20:55Z")

</div>

Could it be, that shift always looks at @timestamp? I'm using my own date field for the date histogram.  
All documents have the same @timestamp, because i just created the index today. If i use a shift \< @timestamp, i get the same as without the shift. If i use a shift \> @timestamp no results are shown.

How can i tell the shift, that my own date field is the field to be shifted by and not @timestamp?

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [December 15, 2022, 1:46pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/9 "2022-12-15T13:46:18Z")

</div>

It should use the field selected in the `date_histogram` configuration.  
You can check it in the Inspector, looking at the Request sent over to Elasticsearch:

```auto
...
"filters": {
          "0": { // current time
            "range": {
              "<my_field_name>": {
                "format": "strict_date_optional_time",
                "gte": "2022-12-14T13:00:00.000Z",
                "lte": "2022-12-15T13:44:32.283Z"
              }
            }
          },
          "31536000000": { // time shift
            "range": {
              "<my_field_time>": {
                "format": "strict_date_optional_time",
                "gte": "2021-12-14T13:00:00.000Z",
                "lte": "2021-12-15T13:44:32.283Z"
              }
            }
          }
...

```

---

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 2:32pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/10 "2022-12-15T14:32:48Z")

</div>

Ah, yes, i found the problem. It only works if i check "bind to global time picker". But if i do that, i have to select last 1 year in order to get the section of the diagram i want.  
But there are other visualizations in the dashboard that get filtered by a control for year. And if the global time picker is set to last 1 year i would only be able to display that data in the other visualizations.

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [December 15, 2022, 2:36pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/11 "2022-12-15T14:36:35Z")

</div>

You can still pin filters for the specific visualization panel in dashboard

---

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 3:19pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/12 "2022-12-15T15:19:16Z")

</div>

What?

So i use my own date field as Timestamp field in the Data View:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/f/ef5d3b500d40e881939ab691069b3d09eb13be31.png)

Then i create the visualization with the shift:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/6/36762f60c3b327b8e998a10031690a0649c776ab.png)

First problem:  
If i set the global time picker to something smaller than the full range, the blue line is no longer just shifted to the side, but also downward and scaled somehow.  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/c/ac4afa3f72489414c290ac1334d16874bb1e3e0e.png)

And even if that was not the case, if i set it to 1 year, the control element only gives 1 year as filter option.  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/3/d32e5cdfdb4bb101eff82c5b22d77dc2ae5db162.png)

But i want to be able to filter a table with this by year. So i have to set it to the full range.  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b2eaf807e2d6114340bce27a764948d9ee5db6ac.png)

If i now select a year, the graph should either show just the line of the filtered year or all lines so the user can manually filter. But what it actually does is show just the data from that year over the full range  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/0/10abee0a6182d8db339d3ef5ac19e17b4b39cfdb.png)

As an alternative, i can use no timestamp field in the data view, but then shift can't be used at all.

So the last thing is to use @timestamp as timestamp field in the data view and select "bind to global time picker"  
So now i can again set the global time picker to last 1 year to get the desired section in the graph.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/8/38a1dba047c5806576a3efeb7d3c7e087df50053.png)  
Again, it's shifted and scaled, but that's another problem.

And now i can also select the years in the control and filter the table with it. But of course this also filters the graph and it shows no more data. Again i would need either all lines or the line of the filter.  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/7/4783c3d1062024eef2dd45ffef8e6be5441e0f0b.png)  
And the next thing is, in a year from now documents will have a timestamp to old to be included.

So i guess what i want to do is just not possible at the moment. (A dashboard with a table that can be filtered by year and a line chart showing either the line from that filtered year or all lines in an interval of 1 year)

---

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 3:41pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/13 "2022-12-15T15:41:33Z")

</div>

I saw that with TSVB it is possible to ignore global filters, but i wasn't able to divide two cumulative sums on the same field with different filters, because the filter can only be set here:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/3/b3a4e9ac3791d2348ea243620779aab1d9b066bb.png)

But my formula requires different filters for "stunden" for the two sums

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/a/ea6aa29af8ebb803b3e88a5178a715c3a2d2a07f.png)

![image](https://us1.discourse-cdn.com/elastic/original/3X/8/9/8983b7c10184aa9c8a2cf396c93ab7fee8cd9f89.png)

No idea how to set the first kql on the first field and the second kql on the second field, if there is only a general filter option.

---

<div class="post-metadata">

### Author: ![Jonas\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_s/32/97631_2.png) [@Jonas\_S](https://discuss.elastic.co/u/Jonas_S)
#### Post date: [December 15, 2022, 5:41pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/14 "2022-12-15T17:41:47Z")

</div>

So in the end i was pretty annoyed, so i just unioned the whole sql two times with itself, shifted by one and two years and gave it an extra flag to filter the records. So now just the current year and the last two ones are availabe, but i don't have to bother with this weird shifting behaviour that is tied to the time picker. So i can filter by year with the control element and just get the 1 year section with the current and last two years each as extra line.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/c/ec12b27393ba758c70a5ae32da8a785d21dec067.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/2/e26769492989c3366a279f5db3d314b4dedf45fb.png)

---

<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: [January 12, 2023, 5:41pm UTC](https://discuss.elastic.co/t/one-line-per-year-with-monthly-buckets-in-line-chart/321294/15 "2023-01-12T17:41:51Z")

</div>

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