# Query to Calculate difference between current and previous values

**URL:** <https://discuss.elastic.co/t/query-to-calculate-difference-between-current-and-previous-values/91911>\
**Category:** Elasticsearch\
**Created:** [July 5, 2017, 1:30pm UTC](https://discuss.elastic.co/t/query-to-calculate-difference-between-current-and-previous-values/91911 "2017-07-05T13:30:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pksingla](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pksingla](https://discuss.elastic.co/u/pksingla)\
**Post date:** [July 5, 2017, 1:30pm UTC](https://discuss.elastic.co/t/query-to-calculate-difference-between-current-and-previous-values/91911/1 "2017-07-05T13:30:46Z")

</div>

I have ingested CPU utilization metric in ES. My requirement is to calculate difference between current and previous CPU value per minute Below is sample data snapshot.

2017-07-2 11:48:40, server1,processor(\_total)-% processor time,3.04,System Processor Time,w3wp,APM2  
2017-07-2 11:49:10, server1,processor(\_total)-% processor time,3.37,System Processor Time,w3wp,APM2

Looking for something like below:  
(y2-y1)/(x2-x1) where y axis is CPU utilization and x-axis is time.  
e.g. (3.37-3.04)/(11:49:10-11:48:40)

Please help in achieving this.

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 5, 2017, 1:35pm UTC](https://discuss.elastic.co/t/query-to-calculate-difference-between-current-and-previous-values/91911/2 "2017-07-05T13:35:30Z")

</div>

I looks like you have already asked this question here: [Compute distance between current and previous value](https://discuss.elastic.co/t/compute-distance-between-current-and-previous-value/91902)

Please do not post the same question multiple times

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 5, 2017, 1:35pm UTC](https://discuss.elastic.co/t/query-to-calculate-difference-between-current-and-previous-values/91911/3 "2017-07-05T13:35:33Z")

</div>


