# Calculate with Kibana metrics

**URL:** https://discuss.elastic.co/t/calculate-with-kibana-metrics/235927
**Category:** Kibana
**Created:** [June 5, 2020, 9:33am UTC](https://discuss.elastic.co/t/calculate-with-kibana-metrics/235927 "2020-06-05T09:33:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![LWine](https://avatars.discourse-cdn.com/v4/letter/l/eada6e/32.png) [@LWine](https://discuss.elastic.co/u/LWine)
#### Post date: [June 5, 2020, 9:33am UTC](https://discuss.elastic.co/t/calculate-with-kibana-metrics/235927/1 "2020-06-05T09:33:59Z")

</div>

I'm working in Kibana. I have an index with each document representing a sold product with product\_quantity, order\_id, customer\_id, order\_date and returned\_quantity. I want to calculate a few things:

1. Average number of orders per customer. Which means I have to calculate unique count of order\_id / unique count of customer\_id.

2. Return rate. Which means I have to calculate sum of returned\_quantity / sum of product\_quantity to divide the number of all returned products by the number of all sold products.

In both cases I am only able to display the single metrics I need (like sum/ unique count) but I am not able to divide them by one another. I read that scripted fields could help but I don't think they can solve those cases plus I do not know how to write those scripts since I have no programming knowledge. Is there any way to do this?

---

<div class="post-metadata">

### Author: ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)
#### Post date: [June 11, 2020, 6:39pm UTC](https://discuss.elastic.co/t/calculate-with-kibana-metrics/235927/2 "2020-06-11T18:39:27Z")

</div>

This is not yet supported. This would be accomplished by using a [bucket script aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html). Please comment on this issue, [https://github.com/elastic/kibana/issues/67405](https://github.com/elastic/kibana/issues/67405), to describe your use case and how you would like to configure the bucket script aggregation for your calculations.

---

<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 9, 2020, 6:39pm UTC](https://discuss.elastic.co/t/calculate-with-kibana-metrics/235927/3 "2020-07-09T18:39:30Z")

</div>

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