# How to shift back just the end datetime in timefitler?

**URL:** <https://discuss.elastic.co/t/how-to-shift-back-just-the-end-datetime-in-timefitler/193436>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [August 2, 2019, 2:50am UTC](https://discuss.elastic.co/t/how-to-shift-back-just-the-end-datetime-in-timefitler/193436 "2019-08-02T02:50:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [August 2, 2019, 2:50am UTC](https://discuss.elastic.co/t/how-to-shift-back-just-the-end-datetime-in-timefitler/193436/1 "2019-08-02T02:50:36Z")

</div>

I have a requirement where I need to calculate the difference from 2 data sets. The two datasets will have different timerange.

ex.  
Dataset1: 2019-01-01 00:00:00 - 2019-07-31 00:00:00  
Dataset2: 2019-01-01 00:00:00 - 2019-08-01 00:00:00 ( \<- specified in timefilter)

What I need to do is below.

(Dataset2: _total count of fieldA_) - (Dataset1: _total count of fieldA_) .

This could be done using transfrom in data object but I also want to dynamically calculate the timerange for **Dataset1**.

Timerange shifting seems to fit my use case but this also slides **the start datetime** as well.

[https://www.elastic.co/guide/en/kibana/7.1/vega-querying-elasticsearch.html](https://www.elastic.co/guide/en/kibana/7.1/vega-querying-elasticsearch.html)

```
          @timestamp: {
            // "%timefilter%" will be replaced with
            // the current values of the time filter
            // (from the upper right corner)
            "%timefilter%": true
            // Only work with %timefilter%
            // Shift current timefilter by 10 units back
            shift: 10
            // week, day (default), hour, minute, second
            unit: minute

```

Can I just shift **the end datetime** of timefilter ?

Thanks,  
Yu Watanabe

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [August 12, 2019, 6:26pm UTC](https://discuss.elastic.co/t/how-to-shift-back-just-the-end-datetime-in-timefitler/193436/2 "2019-08-12T18:26:39Z")

</div>

@nyuriks - can you shed some light here please ?

Thanks  
Rashmi

---

<div class="post-metadata">

**Author:** ![nyuriks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nyuriks/32/26171_2.png) [@nyuriks](https://discuss.elastic.co/u/nyuriks)\
**Post date:** [August 14, 2019, 12:42am UTC](https://discuss.elastic.co/t/how-to-shift-back-just-the-end-datetime-in-timefitler/193436/3 "2019-08-14T00:42:04Z")

</div>

Hi @YuWatanabe, I don't think this is possible at the moment, but it is definitely sounds like an interesting feature to have. Could you create an issue in github, possibly proposing the syntax. And of course any pull requests would be welcome 🙂

---

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [August 16, 2019, 1:37am UTC](https://discuss.elastic.co/t/how-to-shift-back-just-the-end-datetime-in-timefitler/193436/4 "2019-08-16T01:37:43Z")

</div>

@nyuriks

Thanks for the follow up.  
As a matter of fact, I found 2 similar issues in github issues.

### [Vega] Use Kibana dashboard time filter context anywhere in Vega / Vega-lite spec

> <https://github.com/elastic/kibana/issues/20872>

### [VEGA] enhance %timefilter% expansion features

> <https://github.com/elastic/kibana/issues/24412>

Both using below syntax which I really wanted and these are now implemented and founded on [doc](https://www.elastic.co/guide/en/kibana/7.1/vega-querying-elasticsearch.html) too. Its a shame that I did not realize about this ...

```auto
{ %timefilter%: "min" }
{ %timefilter%: "max" }

```

Something like below should work for my case.

### Timefilter for Dataset 1

```auto
"query": {
  "range": {
    "@timestamp": { 
      from: {%timefilter%: "min"},
      to: {%timefilter%: "max", shift: -1, unit: day}
    }
  }
}

```

### Timefilter for Dataset2

```auto
"query": {
  "range": {
    "@timestamp": { 
      from: {%timefilter%: "min"},
      to: {%timefilter%: "max"}
    }
  }
}

```

---

<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:** [September 13, 2019, 1:37am UTC](https://discuss.elastic.co/t/how-to-shift-back-just-the-end-datetime-in-timefitler/193436/5 "2019-09-13T01:37:46Z")

</div>

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