# How can I get the most recent value in a 'Metric'

**URL:** <https://discuss.elastic.co/t/how-can-i-get-the-most-recent-value-in-a-metric/347641>\
**Category:** Kibana\
**Created:** [November 21, 2023, 2:08pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-most-recent-value-in-a-metric/347641 "2023-11-21T14:08:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Negan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/negan/32/127871_2.png) [@Negan](https://discuss.elastic.co/u/Negan)\
**Post date:** [November 21, 2023, 2:08pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-most-recent-value-in-a-metric/347641/1 "2023-11-21T14:08:31Z")

</div>

Hello all!

Currently trying to get the most recent value of a transactiondurationtime. I got a data table with the

name of transaction, average transaction duration, recent transaction duration (which I need to have/calculate)

I only get the options such as average, count, max, min but not recent. There is an advanced option for a JSON input but I cannot find a way to get this working. The field name is transactionduration.

---

<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:** [November 21, 2023, 3:04pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-most-recent-value-in-a-metric/347641/2 "2023-11-21T15:04:29Z")

</div>

Hi @Negan Welcome to the community.

What version are you on?

Can you give some samples of your data and what you want for the expected results?

---

<div class="post-metadata">

**Author:** ![Negan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/negan/32/127871_2.png) [@Negan](https://discuss.elastic.co/u/Negan)\
**Post date:** [November 22, 2023, 7:36am UTC](https://discuss.elastic.co/t/how-can-i-get-the-most-recent-value-in-a-metric/347641/3 "2023-11-22T07:36:28Z")

</div>

Hi yes;

testname.keyword, transactionduration (average)  
test1, 5.158  
test2, 5.018  
test3, 5.14

And now I want for each test1, test2, test3 the most recent transactionduration in milliseconds.  
more than this I cannot give away for data.

---

<div class="post-metadata">

**Author:** ![Negan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/negan/32/127871_2.png) [@Negan](https://discuss.elastic.co/u/Negan)\
**Post date:** [November 22, 2023, 7:45am UTC](https://discuss.elastic.co/t/how-can-i-get-the-most-recent-value-in-a-metric/347641/4 "2023-11-22T07:45:09Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/3/9/396153fdbaa5dc86e1f4e28cb9ad6120077556b8.png)

---

<div class="post-metadata">

**Author:** ![vincenbr](https://avatars.discourse-cdn.com/v4/letter/v/8edcca/32.png) [@vincenbr](https://discuss.elastic.co/u/vincenbr)\
**Post date:** [November 22, 2023, 9:28am UTC](https://discuss.elastic.co/t/how-can-i-get-the-most-recent-value-in-a-metric/347641/5 "2023-11-22T09:28:03Z")

</div>

Hi,  
in Aggregation-based visualisation (the one you show) you can use a "[top metric](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-metrics.html)" aggregation on the field you want (transactionduration) sorted by timestamp descending. It does what you need.  
You can also (even easier) do the visualization in Lens, there is a Last Value function for that.

---

<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:** [December 20, 2023, 9:28am UTC](https://discuss.elastic.co/t/how-can-i-get-the-most-recent-value-in-a-metric/347641/6 "2023-12-20T09:28:24Z")

</div>

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