# Subtract values for consecutive events

**URL:** <https://discuss.elastic.co/t/subtract-values-for-consecutive-events/142056>\
**Category:** Logstash\
**Created:** [July 29, 2018, 6:02am UTC](https://discuss.elastic.co/t/subtract-values-for-consecutive-events/142056 "2018-07-29T06:02:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![karnamonkster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karnamonkster/32/67266_2.png) [@karnamonkster](https://discuss.elastic.co/u/karnamonkster)\
**Post date:** [July 29, 2018, 6:02am UTC](https://discuss.elastic.co/t/subtract-values-for-consecutive-events/142056/1 "2018-07-29T06:02:48Z")

</div>

Hi,

A newbie question  
Version:  
ES - 5.6.2  
Kibana - 5.6.2  
Logstash - 5.6.4  
I have following data pulled from MySQL database using JDBC input  
There are multiple meters with unique meter ID.

```
Time value MeterID id  
July 28th 2018, 23:30:00.000	10,831.872	16200747	596,157
July 28th 2018, 23:15:00.000	10,831.626	16200747	596,148
July 28th 2018, 23:00:00.000	10,831.283	16200747	596,139

```

I need to display & calculate the consumption for the all the MeterIDs and also for each meterid, lets say hourly or daily something like  
[value - value(1 hour before)]  
[value - value(1 day before)]  
Now i need to know what should be best way to achieve this through logstash or kibana

Thanks

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 29, 2018, 10:51am UTC](https://discuss.elastic.co/t/subtract-values-for-consecutive-events/142056/2 "2018-07-29T10:51:51Z")

</div>

Look at the [aggregate](https://www.elastic.co/guide/en/logstash/current/plugins-filters-aggregate.html) filter.

---

<div class="post-metadata">

**Author:** ![karnamonkster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karnamonkster/32/67266_2.png) [@karnamonkster](https://discuss.elastic.co/u/karnamonkster)\
**Post date:** [July 30, 2018, 3:16am UTC](https://discuss.elastic.co/t/subtract-values-for-consecutive-events/142056/3 "2018-07-30T03:16:37Z")

</div>

Hi @Badger,

Thanks for your response, however i would really appreciate if you could outline an example with my use case.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 30, 2018, 2:56pm UTC](https://discuss.elastic.co/t/subtract-values-for-consecutive-events/142056/4 "2018-07-30T14:56:44Z")

</div>

Is your data sorted by MeterId? If they are, then follow [example 4](https://www.elastic.co/guide/en/logstash/current/plugins-filters-aggregate.html#plugins-filters-aggregate-example4). If not I would follow [example 5](https://www.elastic.co/guide/en/logstash/current/plugins-filters-aggregate.html#plugins-filters-aggregate-example5).

---

<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:** [August 27, 2018, 2:56pm UTC](https://discuss.elastic.co/t/subtract-values-for-consecutive-events/142056/5 "2018-08-27T14:56:54Z")

</div>

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