# KQL Query Date filter on non timeseries data

**URL:** <https://discuss.elastic.co/t/kql-query-date-filter-on-non-timeseries-data/321839>\
**Category:** Kibana\
**Tags:** kql-kibana-query-language\
**Created:** [December 22, 2022, 1:10pm UTC](https://discuss.elastic.co/t/kql-query-date-filter-on-non-timeseries-data/321839 "2022-12-22T13:10:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Rodman](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Mark\_Rodman](https://discuss.elastic.co/u/Mark_Rodman)\
**Post date:** [December 22, 2022, 1:10pm UTC](https://discuss.elastic.co/t/kql-query-date-filter-on-non-timeseries-data/321839/1 "2022-12-22T13:10:26Z")

</div>

Hi,  
I'm tying to use Lens to plot data changing over a period of time. We generate the data once a week at single point in time, and so it doesn't look good as a time series. We also want to plot the count of a data point known as `version` which can have around 15 different values. I'm therefore plotting count of `version` as a series (x axis) within a Bar vertical.

I have my initial x series count plot in Lens using the following formula;

```auto
count(kql='general.lastContactTime >= "now-30d" and date_iso >= "now-7d"'

```

`date_iso` defines when the data capture occurs,  
`lastContactTime` is used to filter the data and drop stale records.  
The above is also configured with a Last 30 days date range.

I'm trying to get a second series on the x axis which picks out the previous weeks data as a comparison.

Something along the lines of

```auto
count(kql='general.lastContactTime >= "now-30d" and date_iso >= "(now-7d) -14d"'

```

But that doesn't appear to be a legal query.  
Any chance of some guidance on how to structure the second series?  
Thanks

---

<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 22, 2022, 3:07pm UTC](https://discuss.elastic.co/t/kql-query-date-filter-on-non-timeseries-data/321839/2 "2022-12-22T15:07:19Z")

</div>

Hi @Mark_Rodman

have you tried already the `shift` option?  
It would be something like: `count(kql='...', shift="2w")`

---

<div class="post-metadata">

**Author:** ![Mark\_Rodman](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Mark\_Rodman](https://discuss.elastic.co/u/Mark_Rodman)\
**Post date:** [December 22, 2022, 5:01pm UTC](https://discuss.elastic.co/t/kql-query-date-filter-on-non-timeseries-data/321839/3 "2022-12-22T17:01:18Z")

</div>

I believe shift requires a time series dataset and also can't be applied to differing series.

Thanks for the suggestion though.

---

<div class="post-metadata">

**Author:** ![Mark\_Rodman](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Mark\_Rodman](https://discuss.elastic.co/u/Mark_Rodman)\
**Post date:** [January 4, 2023, 11:41am UTC](https://discuss.elastic.co/t/kql-query-date-filter-on-non-timeseries-data/321839/4 "2023-01-04T11:41:36Z")

</div>

I'm still struggling with this, and I hate to be cheeky, but I don't suppose anyone else has some suggestions.  
Thanks

---

<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:** [January 9, 2023, 10:44am UTC](https://discuss.elastic.co/t/kql-query-date-filter-on-non-timeseries-data/321839/5 "2023-01-09T10:44:56Z")

</div>

The shift feature requires the usage of at least one time field in the configuration, not necessarily a dataView with a time field configured.  
You could define a `Break down` dimension with a date histogram based on your time field, collapsed by `Sum` to hide the actual break down. That should make the `shift` feature work in the formula.

---

<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:** [February 6, 2023, 10:45am UTC](https://discuss.elastic.co/t/kql-query-date-filter-on-non-timeseries-data/321839/6 "2023-02-06T10:45:05Z")

</div>

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