# Count and unique count

**URL:** https://discuss.elastic.co/t/count-and-unique-count/163076
**Category:** Kibana
**Created:** [January 6, 2019, 1:31pm UTC](https://discuss.elastic.co/t/count-and-unique-count/163076 "2019-01-06T13:31:16Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Apple23](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@Apple23](https://discuss.elastic.co/u/Apple23)
#### Post date: [January 6, 2019, 1:31pm UTC](https://discuss.elastic.co/t/count-and-unique-count/163076/1 "2019-01-06T13:31:17Z")

</div>

i want a metric visualisation that finds the difference of count and unique count that is to get the count of duplicates in an index

---

<div class="post-metadata">

### Author: ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)
#### Post date: [January 7, 2019, 11:56am UTC](https://discuss.elastic.co/t/count-and-unique-count/163076/2 "2019-01-07T11:56:50Z")

</div>

You can use Visual Builder to show the amount of duplicates by bucket. So the metric will show the amount of duplicates in the latest time interval.  
 ![duplicates](https://us1.discourse-cdn.com/elastic/original/3X/5/e/5e05dc8074eebd17dbb37565c90baabe601a3586.png)

If you want to show a total number of duplicates, the accurate way would be to increase the bucket so much that it basically contains all the data.

If you try and do cumulative sum of count and cumulative sum of unique values with regular sized buckets, the count will be accurate, but the unique values will begin to go out of sync from the first time you move to the next bucket so that is not a solution.

---

<div class="post-metadata">

### Author: ![user\_kibana](https://avatars.discourse-cdn.com/v4/letter/u/dfb087/32.png) [@user\_kibana](https://discuss.elastic.co/u/user_kibana)
#### Post date: [January 16, 2019, 12:21pm UTC](https://discuss.elastic.co/t/count-and-unique-count/163076/3 "2019-01-16T12:21:58Z")

</div>

Hi, I have the same question and I tried to use Visual Builder as you suggested here however I get a error message saying "Unknown variable: params.count-params.unique\_count" as soon as I choose the field 'Count' in the second box on the right under the Variables. What do I do wrong?

---

<div class="post-metadata">

### Author: ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)
#### Post date: [January 21, 2019, 3:04pm UTC](https://discuss.elastic.co/t/count-and-unique-count/163076/4 "2019-01-21T15:04:21Z")

</div>

Do them in order, so write the expression last. It's because TSVB is set to auto-run and it will try an run before all the variables are set

---

<div class="post-metadata">

### Author: ![user\_kibana](https://avatars.discourse-cdn.com/v4/letter/u/dfb087/32.png) [@user\_kibana](https://discuss.elastic.co/u/user_kibana)
#### Post date: [January 22, 2019, 1:52pm UTC](https://discuss.elastic.co/t/count-and-unique-count/163076/5 "2019-01-22T13:52:50Z")

</div>

Thank you Marius!

---

<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 19, 2019, 1:52pm UTC](https://discuss.elastic.co/t/count-and-unique-count/163076/6 "2019-02-19T13:52:55Z")

</div>

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