# Reference the count of a field name in metrics

**URL:** https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061
**Category:** Metrics
**Tags:** elastic-stack-monitoring
**Created:** [March 3, 2021, 7:22am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061 "2021-03-03T07:22:35Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 3, 2021, 7:22am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/1 "2021-03-03T07:22:35Z")

</div>

I would like to have calculation like you see in the image.

 ![grafik](https://us1.discourse-cdn.com/elastic/original/3X/f/3/f333b4f15da6ccb8dbfe04fe2287878af0a5cb59.png)

How to solve that?

I was trying:

```
{
  "script" : 
    {
    "lang": "painless",
    "inline": "_value * params.manualSeconds / params.correction / params.factorCount",
    "params" : {
      "manualSeconds" : 600,
      "correction" : 100,
      "factorCount" : count('FIELDNAME')
    }
  }
}

```

But does not work.

---

<div class="post-metadata">

### Author: ![rhodesjason](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rhodesjason/32/35639_2.png) [@rhodesjason](https://discuss.elastic.co/u/rhodesjason)
#### Post date: [March 3, 2021, 5:09pm UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/2 "2021-03-03T17:09:40Z")

</div>

@kwoxer thanks for your question. We'd like to route this to the right team. Can you tell us more about what part of Kibana (and what version) you are using for this?

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 4, 2021, 8:39am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/3 "2021-03-04T08:39:11Z")

</div>

Sure, here the info:

- Kibana v 7.8.1

And part of Kibana? Well I just want to create some calculations. So in this example I have a timespan and want to know how much time my robot saved compared to when a human would have done it.

So as you can see the robot ran **3 times**. And the **average completion rate** is **60%** (where the robot stopped at in the process, e.g. stopping because there was data missing or so), that 60% value came from 80%, 50% and 50% btw. The **Seconds Saved** stands for how much seconds the robot saved. So as example the manual run of 100% of the process takes 600 seconds. So the 60% of 600 are the **360 seconds**. And finally the **Seconds Saved \* Count** are what I'm interested in. So currently I only know how much one is saving. Now I want to **multiply** it **with** the overall **Count**.

So At the end it would also be fine to only see one value. But this with the table is also very interesting. I would like to have both actually.

How to do that?

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 4, 2021, 8:46am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/4 "2021-03-04T08:46:36Z")

</div>

Ohh and I also tried to use the Metric explorer but the Chart is always empty. And I also didn't find out any tutorial that helped me there. Not sure what I do incorrect there. I tried out any different Average and graph per and so on:

 ![grafik](https://us1.discourse-cdn.com/elastic/original/3X/0/a/0a123ca1994972899df6ccc2ee8c200ad7aed220.png)

---

<div class="post-metadata">

### Author: ![simianhacker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simianhacker/32/3383_2.png) [@simianhacker](https://discuss.elastic.co/u/simianhacker)
#### Post date: [March 5, 2021, 5:43pm UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/5 "2021-03-05T17:43:13Z")

</div>

@kwoxer Is `STATISTIC-TRANSACTION-COMPLETE-RATE`a scripted field you created in an index pattern? If so, the Metrics Explorer doesn't have support for those fields... yet. We are working on integrating with Kibana index patterns and ultimately the new runtime fields implementation which will be perfect for stuff like this.

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 7, 2021, 9:41am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/6 "2021-03-07T09:41:08Z")

</div>

Nop, its a normal field. Is there no way in referencing like a described in my example above?

---

<div class="post-metadata">

### Author: ![simianhacker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simianhacker/32/3383_2.png) [@simianhacker](https://discuss.elastic.co/u/simianhacker)
#### Post date: [March 8, 2021, 3:23pm UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/7 "2021-03-08T15:23:27Z")

</div>

Not for Metrics Explorer, you can do that using TSVB (under Visualizations). We are working on supporting runtime fields via Kibana index patterns. Unfortunately, I don't have a timeline for when that will be released.

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 9, 2021, 7:47am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/8 "2021-03-09T07:47:26Z")

</div>

> [@simianhacker](#):
>
> TSVB

Good to know, yes that is looking kind of what I need. But now how to reference the count? Really hard to understand. Or is it impossible with the TSVB?

 ![grafik](https://us1.discourse-cdn.com/elastic/original/3X/9/7/979a51dff3f870bc275965ec07f749067a4f5c01.png)

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 9, 2021, 8:11am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/9 "2021-03-09T08:11:43Z")

</div>

I just solved my issue kind of with the Sum of a Scripted field. But as Scripted fields are slower and very static I would more prefer a better way if possible. Also I also need this 1680 seconds value as visualization. Sure I could now hide the other values simply but it will still remain as a table. I would rather prefer a vis of the metrics showing big value. Any tips on this?

 ![grafik](https://us1.discourse-cdn.com/elastic/original/3X/f/a/fa4d430c7669f0fd5bc7b2e1bf915c634d8d87c6.png)

---

<div class="post-metadata">

### Author: ![simianhacker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simianhacker/32/3383_2.png) [@simianhacker](https://discuss.elastic.co/u/simianhacker)
#### Post date: [March 9, 2021, 4:55pm UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/10 "2021-03-09T16:55:12Z")

</div>

What about using a bucket script? Since it's a pipeline aggregation it is only operating on aggregated data so you shouldn't see a performance hit.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/8/68b4d209f1bd2cff43acb928d5870a831ea20cd9.png)

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 10, 2021, 2:58pm UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/11 "2021-03-10T14:58:19Z")

</div>

Cool that worked.

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

Maybe the last question. As you can see on SCANUC process, when there is no field in the TimeSpan. Is there any way to just show a 0 maybe instead of no data?

But this is really just cosmetic, overall it works have many thanks.

---

<div class="post-metadata">

### Author: ![simianhacker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simianhacker/32/3383_2.png) [@simianhacker](https://discuss.elastic.co/u/simianhacker)
#### Post date: [March 10, 2021, 4:45pm UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/12 "2021-03-10T16:45:43Z")

</div>

Is that a TSVB visualization?

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 11, 2021, 7:51am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/13 "2021-03-11T07:51:47Z")

</div>

Yes it is.

---

<div class="post-metadata">

### Author: ![simianhacker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simianhacker/32/3383_2.png) [@simianhacker](https://discuss.elastic.co/u/simianhacker)
#### Post date: [March 11, 2021, 6:02pm UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/14 "2021-03-11T18:02:54Z")

</div>

That happens where there is ZERO rows returned. Maybe we need a "No Data" view or a way to configure it so either it shows the default "No data" message or just displays ZERO for the value.

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 12, 2021, 11:52am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/15 "2021-03-12T11:52:46Z")

</div>

Should I open a feature request for this?

But again thanks. But really hidden feature I would say.

---

<div class="post-metadata">

### Author: ![simianhacker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simianhacker/32/3383_2.png) [@simianhacker](https://discuss.elastic.co/u/simianhacker)
#### Post date: [March 15, 2021, 10:58pm UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/16 "2021-03-15T22:58:16Z")

</div>

Yes, if you could open an issue here: [Issues · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues)

---

<div class="post-metadata">

### Author: ![kwoxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwoxer/32/74809_2.png) [@kwoxer](https://discuss.elastic.co/u/kwoxer)
#### Post date: [March 16, 2021, 8:03am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/17 "2021-03-16T08:03:35Z")

</div>

> <https://github.com/elastic/kibana/issues/94671>
>
> Describe the feature:
> Give choice of showing "No data" or a "0" at the TSVB visualization.
> Describe a specific use case for the...

---

<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: [April 13, 2021, 8:03am UTC](https://discuss.elastic.co/t/reference-the-count-of-a-field-name-in-metrics/266061/18 "2021-04-13T08:03:52Z")

</div>

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