# Group by and Sum

**URL:** <https://discuss.elastic.co/t/group-by-and-sum/187299>\
**Category:** Kibana\
**Created:** [June 25, 2019, 10:07am UTC](https://discuss.elastic.co/t/group-by-and-sum/187299 "2019-06-25T10:07:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alchimia](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@alchimia](https://discuss.elastic.co/u/alchimia)\
**Post date:** [June 25, 2019, 10:07am UTC](https://discuss.elastic.co/t/group-by-and-sum/187299/1 "2019-06-25T10:07:00Z")

</div>

hello to everyone,

i currently have this kind of data imported:

```
invoice_number:1
service:tshirt
charge_without_vat:10.68 
invoice_amount:63.49

invoice_number:1
service:polo
charge_without_vat:5.68
invoice_amount:63.49

invoice_number:1
service:additional_service
charge_without_vat:35.10
invoice_amount:63.49

```

I need to group by invoice\_number, sum invoice\_amount and divide the result into customer base number. How can i do using a line visualization? I tried datasweet plugin but it seems not useful for the scope.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [June 26, 2019, 12:28am UTC](https://discuss.elastic.co/t/group-by-and-sum/187299/2 "2019-06-26T00:28:26Z")

</div>

I think you should be able to do this with either Visual Builder or Timelion.

Here's an answer to a similar question.

> [@Calculate average in Kibana visualizations](https://discuss.elastic.co/t/calculate-average-in-kibana-visualizations/152668/2):
>
> Hi, what you are looking for is the bucket script aggregation, which allows you to calculate the outcome of several metric aggregations. This is not yet completely implemented in Kibana, see also [https://github.com/elastic/kibana/issues/4707](https://github.com/elastic/kibana/issues/4707) Nevertheless you could actually achieve that (using Bucket Script aka Calculation) in Visual Builder, where you would just create two sum aggregations (for times and time\_sum) and then create a script, that will divide those two and draw this one. The sam…

---

<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:** [July 24, 2019, 12:28am UTC](https://discuss.elastic.co/t/group-by-and-sum/187299/3 "2019-07-24T00:28:39Z")

</div>

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