# Sum aggregation along with Unique Count aggregation

**URL:** <https://discuss.elastic.co/t/sum-aggregation-along-with-unique-count-aggregation/26802>\
**Category:** Kibana\
**Created:** [August 4, 2015, 2:27pm UTC](https://discuss.elastic.co/t/sum-aggregation-along-with-unique-count-aggregation/26802 "2015-08-04T14:27:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanju1323](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sanju1323](https://discuss.elastic.co/u/sanju1323)\
**Post date:** [August 4, 2015, 2:27pm UTC](https://discuss.elastic.co/t/sum-aggregation-along-with-unique-count-aggregation/26802/1 "2015-08-04T14:27:22Z")

</div>

Hi,

I have a query regarding Sum and Unique Count aggregations.

I have fields "Total", "ID", "Date".

"Date" "ID" "Total"  
"2013-05-14 14:30:10.02" "1" "2000"  
"2013-05-14 14:30:10.02" "1" "2000"  
"2013-05-14 14:30:10.02" "1" "2000"  
"2013-05-14 14:30:10.02" "1" "2000"  
"2013-05-14 14:30:10.02" "2" "4000"  
"2013-05-14 14:30:10.02" "2" "4000"  
"2013-05-14 14:30:10.02" "2" "4000"  
"2013-05-14 14:30:10.02" "4" "2000"  
"2013-05-14 14:30:10.02" "4" "2000"  
"2013-05-14 14:30:10.02" "4" "2000"

Here, I need sum(Total) based on the unique ID

Is there a way to do it in kibana???

Thanks,  
Sanjay Reddy

---

<div class="post-metadata">

**Author:** ![asafyigal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asafyigal/32/685_2.png) [@asafyigal](https://discuss.elastic.co/u/asafyigal)\
**Post date:** [August 4, 2015, 2:47pm UTC](https://discuss.elastic.co/t/sum-aggregation-along-with-unique-count-aggregation/26802/2 "2015-08-04T14:47:52Z")

</div>

Yes,

If you just want the data use the datatable visualization, in the metric have the sum of the total and in the buckets select split row by term and use the ID.

Hope that help.

-- Asaf.

---

<div class="post-metadata">

**Author:** ![sanju1323](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sanju1323](https://discuss.elastic.co/u/sanju1323)\
**Post date:** [August 4, 2015, 3:01pm UTC](https://discuss.elastic.co/t/sum-aggregation-along-with-unique-count-aggregation/26802/3 "2015-08-04T15:01:17Z")

</div>

Hi @asafyigal

Thanks for the quick reply 😄

As the Total is repeating for the same ID, sum is varying. So, I need like this

Sum(ID=1) =2000 and not 8000  
Sum(ID=2) = 4000 and not 12000  
Sum(ID=4) = 2000 and not 6000

which means I need Sum(Unique Total) for Unique ID

Is it possible ???

---

<div class="post-metadata">

**Author:** ![asafyigal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asafyigal/32/685_2.png) [@asafyigal](https://discuss.elastic.co/u/asafyigal)\
**Post date:** [August 4, 2015, 3:26pm UTC](https://discuss.elastic.co/t/sum-aggregation-along-with-unique-count-aggregation/26802/4 "2015-08-04T15:26:52Z")

</div>

@sanju1323 - Sure

Just use the average aggregation on the metric instead of sum - assuming they have the same value the average will give you what you want.

-- Asaf.

---

<div class="post-metadata">

**Author:** ![sanju1323](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sanju1323](https://discuss.elastic.co/u/sanju1323)\
**Post date:** [August 4, 2015, 3:36pm UTC](https://discuss.elastic.co/t/sum-aggregation-along-with-unique-count-aggregation/26802/5 "2015-08-04T15:36:34Z")

</div>

Thanks @asafyigal

That is fine. But I want this aggregation to be done on the Metrics because I have to perform another aggregations in Buckets.  
So, I need average(Total) by ID in Metrics itself.

I have tried sum(Total) in one Metrics and unique(ID) in another metrics which gives me two different dimensions in the bar graph.

---

<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 6, 2017, 2:15pm UTC](https://discuss.elastic.co/t/sum-aggregation-along-with-unique-count-aggregation/26802/6 "2017-07-06T14:15:22Z")

</div>


