# Is it possible to create a aggregated runtime field and compare them?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-create-a-aggregated-runtime-field-and-compare-them/346205>\
**Category:** Kibana\
**Tags:** runtime\
**Created:** [November 1, 2023, 2:07pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-a-aggregated-runtime-field-and-compare-them/346205 "2023-11-01T14:07:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![turbo23](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/turbo23/32/127124_2.png) [@turbo23](https://discuss.elastic.co/u/turbo23)\
**Post date:** [November 1, 2023, 2:07pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-a-aggregated-runtime-field-and-compare-them/346205/1 "2023-11-01T14:07:13Z")

</div>

Hello,

I want to create a dashboard that shows OK if my data\_stream distinct counted hostnames equals to my distinct counted hostnames in the cmdb index or shows NOK if it no longer equals both values.

My idea: Compare two values from two different data streams. Both fields have to be aggregates first.  
Maybe i can do this with created runtime fields for each data\_stream like distinct\_counted\_hostname1 in data\_stream1 and distinct\_counted\_hostname2 in data\_stream 2.

Also both aggregated field should be recalculated with the latest value, everytime the search runs

I've no idea to create such runtime-fields.  
I know how to calculate it with kibana (unique\_count(hostname) or with DSQL:

```auto
 "aggs": {
    "0": {
      "cardinality": {
        "field": "hostname"
      }
    }
  },

```

Any help or better ideas?

---

<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:** [November 1, 2023, 2:24pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-a-aggregated-runtime-field-and-compare-them/346205/2 "2023-11-01T14:24:21Z")

</div>

Hi @turbo23 ,

welcome to the kibana community.  
I do not think that is possible without a `transforms` pass before to merge the two data streams: [Transforming data | Elasticsearch Guide [8.10] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/transforms.html)

After merging them you would be possible to perform comparison checks at Lens formula level with something like:

`ifelse(unique_count( fieldA ) == unique_count( fieldB ), <value-for-eq>, <value-otherwise>)`

---

<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:** [November 29, 2023, 2:24pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-a-aggregated-runtime-field-and-compare-them/346205/3 "2023-11-29T14:24:53Z")

</div>

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