# Kibana compare two logs based on a log value

**URL:** <https://discuss.elastic.co/t/kibana-compare-two-logs-based-on-a-log-value/334525>\
**Category:** Kibana\
**Created:** [May 28, 2023, 8:14am UTC](https://discuss.elastic.co/t/kibana-compare-two-logs-based-on-a-log-value/334525 "2023-05-28T08:14:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkan](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@mkan](https://discuss.elastic.co/u/mkan)\
**Post date:** [May 28, 2023, 8:14am UTC](https://discuss.elastic.co/t/kibana-compare-two-logs-based-on-a-log-value/334525/1 "2023-05-28T08:14:06Z")

</div>

i have logs that contains a run\_id and type of operation, for each unique run\_id there are two possibilities for operation  
so it looks like this:

```auto
"run_id": ["123"], "operation": ["a"]
"run_id": ["123"], "operation": ["b"]
"run_id": ["456"], "operation": ["a"]
"run_id": ["789"], "operation": ["a"]

```

i want to visualize which precentage of run\_id has logs with both operations, so in the example above it will show me a 33.33% (could be in a number, a stacked bar or a pie chart, doesn't really matter)  
can you do this in kibana?

---

<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:** [May 29, 2023, 9:36am UTC](https://discuss.elastic.co/t/kibana-compare-two-logs-based-on-a-log-value/334525/2 "2023-05-29T09:36:17Z")

</div>

Hi @mkan

welcome to the Kibana community.  
I think the best it can be achieve at the moment is a table with the absolute number of `"run_id"` that satisfy the given criteria:

- Pick the table visualization in Lens
- Configure a `Top Values by "run_id"` of 1000 (or more values) and select the `Collapse by sum` option
  - if you have more than 10000 possible `run_id` values, then I suggest to add a `Custom ranking` column based on `unique count` of `operation`.

- As metric you can use a formula like the following:

```auto
ifelse(
    unique_count(operation.keyword) / overall_max(unique_count(operation.keyword)) == 1
    , 1, 0)

```

 ![Screenshot 2023-05-29 at 11.20.59](https://us1.discourse-cdn.com/elastic/original/3X/9/e/9ea63cc1d0fb21a997b4fb4b2cf14d42f477b8d1.png)

In the formula above I assumed you do not know before hand the exact number of operations that can be applied.  
Unless you know the total number of "run\_id" before hand or via a field (i.e. something like a "current\_running\_ids" field for each record) unfortunately it's not possible to workout the percentage.  
If you have such hypothetical "current\_running\_ids" field then you might compute a ratio in the fomula:

```auto
ifelse(
    unique_count(operation.keyword) / overall_max(unique_count(operation.keyword)) == 1
    , 1, 0) / last_value(current_running_ids)

```

---

<div class="post-metadata">

**Author:** ![mkan](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@mkan](https://discuss.elastic.co/u/mkan)\
**Post date:** [May 30, 2023, 12:40pm UTC](https://discuss.elastic.co/t/kibana-compare-two-logs-based-on-a-log-value/334525/3 "2023-05-30T12:40:24Z")

</div>

Thank you for the response!  
Right now my table visualization looks like this:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/e/ced53bad3cf8f6a78a89bcd6c8b67027f064042b.jpeg)

is there a way for me to not show a user\_id if it only has an operation: “b” log?  
So In that case the red row in the example photo would not appear in the table

---

<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 27, 2023, 12:40pm UTC](https://discuss.elastic.co/t/kibana-compare-two-logs-based-on-a-log-value/334525/4 "2023-06-27T12:40:38Z")

</div>

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