# Kibana Use Date Interval without using Date Histogram

**URL:** <https://discuss.elastic.co/t/kibana-use-date-interval-without-using-date-histogram/276286>\
**Category:** Kibana\
**Tags:** lens\
**Created:** [June 17, 2021, 3:31pm UTC](https://discuss.elastic.co/t/kibana-use-date-interval-without-using-date-histogram/276286 "2021-06-17T15:31:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)\
**Post date:** [June 17, 2021, 3:31pm UTC](https://discuss.elastic.co/t/kibana-use-date-interval-without-using-date-histogram/276286/1 "2021-06-17T15:31:50Z")

</div>

Hi All,

I'm trying to create a visualization, where I have a date field as the columns of a table. I want to have the columns be by week, but don't want to use a date histogram, and instead want to use the dates as intervals with the complete time series.

Is there a way to achieve this without adding an additional field that adds the date by week as a keyword?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [June 18, 2021, 7:42am UTC](https://discuss.elastic.co/t/kibana-use-date-interval-without-using-date-histogram/276286/2 "2021-06-18T07:42:12Z")

</div>

Why do you not want to use date histogram? You can customize the interval used for the date histogram to use weekly buckets.

I'm not sure what you mean by

> use the dates as intervals with the complete time series.

Can you explain how your data looks like and how you want the table to look like?

---

<div class="post-metadata">

**Author:** ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)\
**Post date:** [June 18, 2021, 11:58am UTC](https://discuss.elastic.co/t/kibana-use-date-interval-without-using-date-histogram/276286/3 "2021-06-18T11:58:04Z")

</div>

@flash1293 yeah, I don't think I explained my question very well, so let me try again.

I have data which spans about 2 years (and growing). This data has two fields, `office_name` and `number_of_users`. I want to perform a cumulative sum on the with the entire data range (2 years) by week, but I only want the table to show the last 8 weeks.

Table should look like this:

```auto
| Office Name | 2021-06-06 | 2021-06-13 | etc... |
| Office 1 | cumul. sum | cumul. sum | etc... |
| Office 2 | cumul. sum | cumul. sum | etc... |

```

From what I can tell currently, is that this can only be partially achieved. Either I set the date histogram to 8 weeks (but then my cumulative sum will be off, because it doesn't take into account data before the 8 weeks), or I set the date range to be 2 years, but then have a table with 104 columns (weeks) in it. Another issue with setting the date range to 2 years, is that the data is constantly going so will require constant updating of the time range (while I could set it to something large like 10 years, it wouldn't solve the problem of only wanting to see the last 8 columns (weeks).

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [June 18, 2021, 12:40pm UTC](https://discuss.elastic.co/t/kibana-use-date-interval-without-using-date-histogram/276286/4 "2021-06-18T12:40:38Z")

</div>

Thanks, that's a great explanation.

Unfortunately I don't think there is a good way at the moment to achieve this. I think the best you can get to is the following:

In Lens, switch to datatable and do a top values of the office name for "rows". For metric, do a sum of number of users. For columns, do the following:

- Do a "filters" function with the following filters (assuming your time field is called `timestamp`):
- Label `this week`, KQL: `*`
- Label `- 1 week`, KQL: `timestamp < now-1w`
- Label `- 2 weeks`, KQL: `timestamp < now-2w`
- ...

Note: `now-1w` will subtract 1 week from the current day and hour, it won't start with the beginning of the week. If you want that instead, you can use `now-1w/w`. It's important to not add spaces after `now` and before `1w`.

Add this table to a dashboard and set the time range in the top right to something like "last 10 years" (spanning your whole data range). Save the dashboard with "Store time with dashboard" switch checked, so it will be set automatically when going to the dashboard.

If you have other visualizations on the same dashboard that need the current time range instead of the full data range, you can also overwrite the time range for this panel by setting "Customize time range" in the panel options

This should give you the values you want to see, but with the downside of not getting the resolved dates in the column headers but "-2 weeks" and so on labels

---

<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:** [July 16, 2021, 12:41pm UTC](https://discuss.elastic.co/t/kibana-use-date-interval-without-using-date-histogram/276286/5 "2021-07-16T12:41:27Z")

</div>

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