# How to sum field?

**URL:** <https://discuss.elastic.co/t/how-to-sum-field/214471>\
**Category:** Kibana\
**Created:** [January 9, 2020, 4:50pm UTC](https://discuss.elastic.co/t/how-to-sum-field/214471 "2020-01-09T16:50:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ja123](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@ja123](https://discuss.elastic.co/u/ja123)\
**Post date:** [January 9, 2020, 4:50pm UTC](https://discuss.elastic.co/t/how-to-sum-field/214471/1 "2020-01-09T16:50:26Z")

</div>

I've got many docs in elasticsearch and I want to sum the field `Verspätung` by the field `Linie`.  
When I say Kibana to sum the `Verspätung` , it sums all `Verspätung` fields of `result`. So I got following :

```
Linie Sum_verspätung
S5 82
EC218 82

```

But I want the following.

```
Linie Sum_verspätung
S5 76
EC218 6

```

My docs in ES look like this:

Example doc1:

> {  
> "@old\_timestamp" =\> "2020-01-09T1346",  
> "result" =\> [  
> [0] {  
> "Verspätung" =\> 3,  
> "Linie" =\> "EC218",  
> "ID" =\> "2020-01-09T14:04:00.000Z\_8010101"  
> },  
> [1] {  
> "Bahntyp" =\> "S-Bahn",  
> "Verspätung" =\> 56,  
> "Linie" =\> "S5",  
> "ID" =\> "2020-01-09T14:48:00.000Z\_8006698",  
> }  
> [2] {  
> "Bahntyp" =\> "S-Bahn",  
> "Verspätung" =\> 10,  
> "Linie" =\> "S5",  
> "ID" =\> "2020-01-09T14:48:00.000Z\_8006556",  
> }

Example doc2:

> {  
> "@old\_timestamp" =\> "2020-01-09T1386",  
> "result" =\> [  
> [0] {  
> "Verspätung" =\> 3,  
> "Linie" =\> "EC218",  
> "ID" =\> "2020-01-09T14:04:00.000Z\_8010101"  
> },  
> [1] {  
> "Bahntyp" =\> "S-Bahn",  
> "Verspätung" =\> 10,  
> "Linie" =\> "S5",  
> "ID" =\> "2020-01-09T14:48:00.000Z\_8006698",  
> }

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [January 9, 2020, 6:03pm UTC](https://discuss.elastic.co/t/how-to-sum-field/214471/2 "2020-01-09T18:03:52Z")

</div>

I don't understand it properly your question.  
but if "Verspätung" is integer then  
you should have 3+56+10+3+10 = 82 (which is correct thing)  
and Linie is string you can't sum it.

---

<div class="post-metadata">

**Author:** ![ja123](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@ja123](https://discuss.elastic.co/u/ja123)\
**Post date:** [January 10, 2020, 8:51am UTC](https://discuss.elastic.co/t/how-to-sum-field/214471/3 "2020-01-10T08:51:35Z")

</div>

I want to sum the `Verspätung` values by the different `Linie` and not all  
`Verspätung` values of one doc.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [January 10, 2020, 1:58pm UTC](https://discuss.elastic.co/t/how-to-sum-field/214471/4 "2020-01-10T13:58:47Z")

</div>

then you do sum for value verspatung.  
and then use term filter on Linie

---

<div class="post-metadata">

**Author:** ![joshdover](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshdover/32/42020_2.png) [@joshdover](https://discuss.elastic.co/u/joshdover)\
**Post date:** [January 10, 2020, 11:21pm UTC](https://discuss.elastic.co/t/how-to-sum-field/214471/5 "2020-01-10T23:21:50Z")

</div>

Not sure exactly where you're trying to do this, but you can create this table in with the "Data Table" visualization in Kibana.

The configuration should look like this:

- Under "Metrics" expand the existing count Metric
- On the "Aggregation" drop down select "Sum"
- Under the "Field" drop down select "Verspätung"
- Under the "Buckets" section, click "Add" and then select "Split rows"
- On the "Aggregation" drop down select "Terms"
- On the "Field" drop down select "Linie"
- Change the "Size" option to the number of results you want to look at

Let me know if this doesn't work!

---

<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:** [February 7, 2020, 11:21pm UTC](https://discuss.elastic.co/t/how-to-sum-field/214471/6 "2020-02-07T23:21:51Z")

</div>

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