# How to get the derived metric based on the calculated metric

**URL:** https://discuss.elastic.co/t/how-to-get-the-derived-metric-based-on-the-calculated-metric/93504
**Category:** Kibana
**Created:** [July 18, 2017, 6:28am UTC](https://discuss.elastic.co/t/how-to-get-the-derived-metric-based-on-the-calculated-metric/93504 "2017-07-18T06:28:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![qilifei](https://avatars.discourse-cdn.com/v4/letter/q/6f9a4e/32.png) [@qilifei](https://discuss.elastic.co/u/qilifei)
#### Post date: [July 18, 2017, 6:28am UTC](https://discuss.elastic.co/t/how-to-get-the-derived-metric-based-on-the-calculated-metric/93504/1 "2017-07-18T06:28:23Z")

</div>

I've already get both metrics max(dt) and min(dt) of each transID in the kibana. How shoud I get the duration of each transId by the calculation max(dt) - min(dt) ? I did it by the bucket script in the dev tools as the bottom scripts . But i donot know how to implent it in the kibana. Is there any metric expresson available?

 ![](https://us1.discourse-cdn.com/elastic/original/3X/2/2/227657ef46646c6326f3632a88ef25af9a2e0c04.png)

POST /jun/\_search  
{  
"size": "0",  
"\_source": {  
"includes": [  
"ct"  
]  
},  
"aggs": {  
"eachtransID": {  
"terms": {  
"field": "transID"  
},  
"aggs": {  
"min\_ct": {  
"min": {  
"field": "dt"  
}  
},  
"max\_ct": {  
"max": {  
"field": "dt"  
}  
},  
"date\_diff": {  
" **bucket\_script**": {  
"buckets\_path": {  
"min\_ct1": "min\_ct",  
"max\_ct1": "max\_ct"  
},  
**"script": "params.min\_ct1 - params.max\_ct1"**  
}  
}  
}  
},  
"avg\_ct": {  
"avg\_bucket": {  
"buckets\_path": "eachtransID\>date\_diff"  
}  
}  
}  
}  
}

---

<div class="post-metadata">

### Author: ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)
#### Post date: [July 18, 2017, 8:00am UTC](https://discuss.elastic.co/t/how-to-get-the-derived-metric-based-on-the-calculated-metric/93504/2 "2017-07-18T08:00:57Z")

</div>

metric expression is onlh available in time series visual builder.  
you could also use timelion to do something like that,  
however both with only work with time series data

---

<div class="post-metadata">

### Author: ![qilifei](https://avatars.discourse-cdn.com/v4/letter/q/6f9a4e/32.png) [@qilifei](https://discuss.elastic.co/u/qilifei)
#### Post date: [July 22, 2017, 3:29am UTC](https://discuss.elastic.co/t/how-to-get-the-derived-metric-based-on-the-calculated-metric/93504/3 "2017-07-22T03:29:30Z")

</div>

ok , thanks a lot . I'll try it later

---

<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: [August 19, 2017, 3:30am UTC](https://discuss.elastic.co/t/how-to-get-the-derived-metric-based-on-the-calculated-metric/93504/4 "2017-08-19T03:30:12Z")

</div>

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