# Kibana Average metric taking unique count of another field

**URL:** https://discuss.elastic.co/t/kibana-average-metric-taking-unique-count-of-another-field/96870
**Category:** Kibana
**Created:** [August 13, 2017, 10:26am UTC](https://discuss.elastic.co/t/kibana-average-metric-taking-unique-count-of-another-field/96870 "2017-08-13T10:26:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![parma](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@parma](https://discuss.elastic.co/u/parma)
#### Post date: [August 13, 2017, 10:26am UTC](https://discuss.elastic.co/t/kibana-average-metric-taking-unique-count-of-another-field/96870/1 "2017-08-13T10:26:31Z")

</div>

I need to calculate the average value of a field. But the base is not the number of documents. I need to consider the unique count of another field as base(denominator). Is there any way to achieve this through built-in visualization or through giving calculated script to kibana

---

<div class="post-metadata">

### Author: ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)
#### Post date: [August 14, 2017, 12:59pm UTC](https://discuss.elastic.co/t/kibana-average-metric-taking-unique-count-of-another-field/96870/2 "2017-08-14T12:59:28Z")

</div>

Hi,

You can use scripted field under index patterns to calculate that value and then use it as a base.  
Here are the docs which explain how to do it:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html)  
[https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)

This is a pretty good blogpost which explains all about it:

> **[Using Painless in Kibana scripted fields
	  	 | Elastic](https://www.elastic.co/blog/using-painless-kibana-scripted-fields)**
>
> Kibana provides powerful ways to search and visualize data stored in Elasticsearch. For the purpose of visualizations, Kibana looks for fields defined in Elasticsearch mappings and presents them as op...

Thanks,  
Bhavya

---

<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: [September 11, 2017, 12:59pm UTC](https://discuss.elastic.co/t/kibana-average-metric-taking-unique-count-of-another-field/96870/3 "2017-09-11T12:59:50Z")

</div>

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