# Custom average for unique records

**URL:** https://discuss.elastic.co/t/custom-average-for-unique-records/82988
**Category:** Kibana
**Created:** [April 20, 2017, 6:44am UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988 "2017-04-20T06:44:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![avivc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avivc/32/16501_2.png) [@avivc](https://discuss.elastic.co/u/avivc)
#### Post date: [April 20, 2017, 6:44am UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988/1 "2017-04-20T06:44:38Z")

</div>

HI guys,  
I'm trying to figure out if there's a way to customize the average of my visualizes  
**I.e** , I want the average for the unique records and not the average for all records

> 1,2,3,4,5,6,7,8,8,9  
> The average will refer to 8 numbers due to the fact that 8 appears twice

Any idea how to do this using Kibana's features?

10x in advance

---

<div class="post-metadata">

### Author: ![Stacey\_Gammon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stacey_gammon/32/14025_2.png) [@Stacey\_Gammon](https://discuss.elastic.co/u/Stacey_Gammon)
#### Post date: [April 20, 2017, 3:34pm UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988/2 "2017-04-20T15:34:28Z")

</div>

Just to clarify, the value you want to retrieve from, say, `[1, 7, 7, 10]` is `5` because `7` is completely removed due to the fact that it appeared twice? Or are you looking for the number `6`, because only the unique numbers are counted, and `7` is still included once? I believe you are looking for the former.

Though either way, the only way I can think of accomplishing this is by adjusting your data ingestion to add a field that tracks only numbers that are not duplicates, then you could use the normal average calculation on that field.

You can use a data table visualization to view unique values for a field, and export that data and run calculations externally on it, but I'm not aware of a way to use those unique numbers in a visualization inside Kibana.

---

<div class="post-metadata">

### Author: ![avivc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avivc/32/16501_2.png) [@avivc](https://discuss.elastic.co/u/avivc)
#### Post date: [April 20, 2017, 4:46pm UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988/3 "2017-04-20T16:46:43Z")

</div>

Tnx @Stacey_Gammon for response  
I actually meant to the 2nd - count unique numbers too 😏  
For your 1st suggestion, you actually mean to index my data in ES with unique/ custom field?  
Does single parameter is enough?  
**e.g.**

> 1,2,3,4,5,6,7,8,8,9  
> 1st parameter goes for number of unique values (8) and 2nd parameter goes for the total count of unique nubmers (45)

Else how the normal average will perform proper calculation ?

---

<div class="post-metadata">

### Author: ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)
#### Post date: [April 20, 2017, 5:56pm UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988/4 "2017-04-20T17:56:54Z")

</div>

Hi @avivc,

which version of Kibana are you using and what type of visualization are you trying to create (metric, bar chart, table, ...)?

---

<div class="post-metadata">

### Author: ![avivc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avivc/32/16501_2.png) [@avivc](https://discuss.elastic.co/u/avivc)
#### Post date: [April 23, 2017, 9:36am UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988/5 "2017-04-23T09:36:39Z")

</div>

Hi @weltenwort  
Running Kibana Version: 5.1.2 and the visualization is line chart.

---

<div class="post-metadata">

### Author: ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)
#### Post date: [April 24, 2017, 2:50pm UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988/6 "2017-04-24T14:50:36Z")

</div>

Please correct me if I misunderstand your requirements, but that sounds like a line chart with the `average` aggregation as the y-axis metric and a `terms` aggregation as the x-axis metric on the field with unique values should do the trick. Unless there's another aggregation already on the x-axis...?

---

<div class="post-metadata">

### Author: ![avivc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avivc/32/16501_2.png) [@avivc](https://discuss.elastic.co/u/avivc)
#### Post date: [April 25, 2017, 8:43am UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988/7 "2017-04-25T08:43:29Z")

</div>

Hi @weltenwort  
I'm checking your input  
Tnx

---

<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: [May 23, 2017, 8:44am UTC](https://discuss.elastic.co/t/custom-average-for-unique-records/82988/8 "2017-05-23T08:44:54Z")

</div>

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