# Get sum of created metrics

**URL:** <https://discuss.elastic.co/t/get-sum-of-created-metrics/307311>\
**Category:** Kibana\
**Created:** [June 15, 2022, 5:24pm UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311 "2022-06-15T17:24:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chamod\_maduranga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chamod_maduranga/32/106703_2.png) [@chamod\_maduranga](https://discuss.elastic.co/u/chamod_maduranga)\
**Post date:** [June 15, 2022, 5:24pm UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/1 "2022-06-15T17:24:06Z")

</div>

what i need to get is get top hits for each TYPE and need to get the summation of them.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/1/51f2544b8c704372b8f301d7f945d223a2ead227.png)

For this **example summation should be 25(1+1+1+22).**.Can i get 25 as in one metric visual so that i can add to dashboard as one single visual.

current workflow:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/e/be8baaf2b2aade396f77319457719b02aaacf04a.png)

**Sample data:**

|timestamp ID Name Count

|1/18/2022 |1 |A | **22** |  
|1/17/2022 |2 |A |45 |  
|1/16/2022 |3 |A |2 |  
|1/15/2022 |3 |C | **1** |  
|1/12/2022 |1 |C |8 |  
|1/11/2022 |5 |B | **1** |  
|1/10/2022 |3 |D | **1** |  
|1/09/2022 |1 |B |4 |  
|1/08/2022 |3 |B |2 |

Highlighted values are the top hits(based on timestamp) for each Type. So need to get distinct summation.(22+1+1+1)

So i got the top hits for each catagory and split by type . But i have no idea to get the summation

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 15, 2022, 7:27pm UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/2 "2022-06-15T19:27:22Z")

</div>

Are you really sure you want Top Hits...... top hits is the most common... you just happen to be setting to 1 and getting the last because you are sorting...

Seems if I read your data right you want the Sum of Count for each of the Last Entry based on the timestamp for each Name.... Is that correct?

What version of the Stack are you on?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 16, 2022, 1:42am UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/3 "2022-06-16T01:42:42Z")

</div>

I can show you how to do this..

 ![Screen Shot 2022-06-15 at 6.51.36 PM](https://us1.discourse-cdn.com/elastic/original/3X/7/f/7ff0b8938bcb8c283ea270a811a88ac86535c81c.png)

 ![Screen Shot 2022-06-15 at 6.51.45 PM](https://us1.discourse-cdn.com/elastic/original/3X/9/3/93bf34a512bfdd835bccee082770478e4cebdf97.png)

---

<div class="post-metadata">

**Author:** ![chamod\_maduranga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chamod_maduranga/32/106703_2.png) [@chamod\_maduranga](https://discuss.elastic.co/u/chamod_maduranga)\
**Post date:** [June 16, 2022, 3:24am UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/4 "2022-06-16T03:24:08Z")

</div>

Yaa. You got it right. But need to show only 25 as a visual. Other things should not disply. Only the summation value need to be displayed. Not a table.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 16, 2022, 3:59am UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/5 "2022-06-16T03:59:53Z")

</div>

Not sure how to do it without the table and TSVB does not have that last value in it as far as I know. So I'm not sure how to do that today.

If I get a chance I'll poke at it some more.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [June 16, 2022, 7:25am UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/6 "2022-06-16T07:25:35Z")

</div>

If you know beforehand each type name I guess you can use Lens formula for that in a Metric visualization?

```auto
last_value( Count, kql='Name: A') + last_value( Count, kql='Name: B') + last_value( Count, kql='Name: C') + etc...

```

---

<div class="post-metadata">

**Author:** ![chamod\_maduranga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chamod_maduranga/32/106703_2.png) [@chamod\_maduranga](https://discuss.elastic.co/u/chamod_maduranga)\
**Post date:** [June 16, 2022, 9:51am UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/7 "2022-06-16T09:51:10Z")

</div>

> [@Marco\_Liberati](#):
>
> `last_value( Count, kql='Name: A') + last_value( Count, kql='Name: B') + last_value( Count, kql='Name: C') + etc...`

Hi,

Cant see the Lens?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/3/03966e714ee7edeb17df0a9747d7f417ffbfc9d4.png)

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [June 16, 2022, 10:11am UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/8 "2022-06-16T10:11:18Z")

</div>

What version of the stack do you have?

---

<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 14, 2022, 10:11am UTC](https://discuss.elastic.co/t/get-sum-of-created-metrics/307311/9 "2022-07-14T10:11:45Z")

</div>

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