# Count on last appearance of each type

**URL:** https://discuss.elastic.co/t/count-on-last-appearance-of-each-type/233727
**Category:** Kibana
**Created:** [May 21, 2020, 11:10am UTC](https://discuss.elastic.co/t/count-on-last-appearance-of-each-type/233727 "2020-05-21T11:10:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cjabrantes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjabrantes/32/78091_2.png) [@cjabrantes](https://discuss.elastic.co/u/cjabrantes)
#### Post date: [May 21, 2020, 11:10am UTC](https://discuss.elastic.co/t/count-on-last-appearance-of-each-type/233727/1 "2020-05-21T11:10:42Z")

</div>

Hi all,

Having this data:  
Time type status  
May 21, 2020 @ 11:40:48.345 A 1  
May 21, 2020 @ 11:40:48.344 B 1  
May 21, 2020 @ 11:40:48.344 C 0  
May 21, 2020 @ 11:35:23.012 A 1  
May 21, 2020 @ 11:35:23.012 B 0  
May 21, 2020 @ 11:35:23.012 C 0  
May 21, 2020 @ 11:30:32.345 A 1  
May 21, 2020 @ 11:30:32.344 B 0  
May 21, 2020 @ 11:30:32.344 C 0

My objective is to count the number of 1 in status field, but only in the last occurence of each type. So in this case 2.

I was trying to do it in TSVB Metric, with "Last value" in "Data timerange mode", set interval to 5m, but it does not seem to be working, which leads me to the question:

How the "Last value" works? I saw the:  
`Last value` will match only the documents for the specified interval from the end of the time range. but not sure what it means in my case.

Is this possible to archive my goal?

Thanks for the help,

---

<div class="post-metadata">

### Author: ![cjabrantes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjabrantes/32/78091_2.png) [@cjabrantes](https://discuss.elastic.co/u/cjabrantes)
#### Post date: [May 21, 2020, 12:52pm UTC](https://discuss.elastic.co/t/count-on-last-appearance-of-each-type/233727/2 "2020-05-21T12:52:00Z")

</div>

Well, seems to work fine after select the right timestamp field.

Thanks,

---

<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: [June 18, 2020, 12:52pm UTC](https://discuss.elastic.co/t/count-on-last-appearance-of-each-type/233727/3 "2020-06-18T12:52:04Z")

</div>

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