# Plot time shift line from 4 previous week

**URL:** <https://discuss.elastic.co/t/plot-time-shift-line-from-4-previous-week/369297>\
**Category:** Kibana\
**Created:** [October 23, 2024, 4:55pm UTC](https://discuss.elastic.co/t/plot-time-shift-line-from-4-previous-week/369297 "2024-10-23T16:55:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gueri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gueri/32/103243_2.png) [@gueri](https://discuss.elastic.co/u/gueri)\
**Post date:** [October 23, 2024, 4:55pm UTC](https://discuss.elastic.co/t/plot-time-shift-line-from-4-previous-week/369297/1 "2024-10-23T16:55:50Z")

</div>

Hello

See my viz below:

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/6/1/618f1e27ce7e7ca9a63c7761c46ee7becd3bb4bc.png)

The shaded blue area is the count of 15 window time shifted 1 week ago

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/1/5/158e25f421dcbf6d1733ab0272b59767bdd17eaf.png)

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/1/4/145ad3a7cdf6774c48e26766b9f48fd13c82f4a8.png)

Now I want the average count from 4 previous week.

For example , the April 2 12:15pm:

the green line is the count of 15 min windows (no change)

but the blue line must be the average of :

- count of 15 min windows for March 26 12:15pm
- count of 15 min windows for March 19 12:15pm
- count of 15 min windows for March 12 12:15pm
- count of 15 min windows for March 5 12:15pm

My Kibana version is 8.15.2. How to do that ?

Regards

---

<div class="post-metadata">

**Author:** ![gueri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gueri/32/103243_2.png) [@gueri](https://discuss.elastic.co/u/gueri)\
**Post date:** [October 28, 2024, 3:15pm UTC](https://discuss.elastic.co/t/plot-time-shift-line-from-4-previous-week/369297/2 "2024-10-28T15:15:23Z")

</div>

Hi!  
I think I found a solution. I use a formula like this :

> round(  
> (defaults(count(shift='1w'),0) +  
> defaults(count(shift='2w'),0) +  
> defaults(count(shift='3w'),0) +  
> defaults(count(shift='4w'),0))  
> /  
> (ifelse(defaults(count(shift='1w'),-1)\< 0,0,1) +  
> ifelse(defaults(count(shift='2w'),-1)\< 0,0,1) +  
> ifelse(defaults(count(shift='3w'),-1)\< 0,0,1) +  
> ifelse(defaults(count(shift='4w'),-1)\< 0,0,1))  
> )
