# Subtract document count for different field names in Kibana

**URL:** <https://discuss.elastic.co/t/subtract-document-count-for-different-field-names-in-kibana/166767>\
**Category:** Kibana\
**Created:** [February 1, 2019, 5:39pm UTC](https://discuss.elastic.co/t/subtract-document-count-for-different-field-names-in-kibana/166767 "2019-02-01T17:39:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natalia\_Kuleniuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/natalia_kuleniuk/32/43727_2.png) [@Natalia\_Kuleniuk](https://discuss.elastic.co/u/Natalia_Kuleniuk)\
**Post date:** [February 1, 2019, 5:39pm UTC](https://discuss.elastic.co/t/subtract-document-count-for-different-field-names-in-kibana/166767/1 "2019-02-01T17:39:54Z")

</div>

Hi,

I have following easy schema of my ES document:

videoAsin  
eventName

**Video asin i** s unique identifier of video we store.  
**eventName** may have different values. For example, “event1”, “event2”, “event3”, etc

**I need to get following dashboard in Kibana:**

For each **videoAsin** , get count of documents with **eventName = “event1”** and **_subtract_** count of documents with **eventName = “event2”** for the same videoAsin.

Is it possible to achieve so using Kibana? I have newest version

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [February 22, 2019, 3:45pm UTC](https://discuss.elastic.co/t/subtract-document-count-for-different-field-names-in-kibana/166767/2 "2019-02-22T15:45:43Z")

</div>

Hello,  
A solution that I came up with would be to create a scripted field that is something like this:

```auto
if doc["eventName"] == "event1" {
return 1 } 
if doc["eventName"] == "event2" {
return -1}
return 0

```

Now you can do a chart with a Sum metric on the scripted field and a split by Terms on videoAsin.

---

<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:** [March 22, 2019, 3:49pm UTC](https://discuss.elastic.co/t/subtract-document-count-for-different-field-names-in-kibana/166767/3 "2019-03-22T15:49:29Z")

</div>

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