# Calculating percentage in visualization per a specific field and not the regular one

**URL:** <https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153>\
**Category:** Kibana\
**Tags:** lens, visualisation\
**Created:** [May 23, 2023, 8:24pm UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153 "2023-05-23T20:24:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Halfon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/halfon/32/121353_2.png) [@Halfon](https://discuss.elastic.co/u/Halfon)\
**Post date:** [May 23, 2023, 8:24pm UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153/1 "2023-05-23T20:24:37Z")

</div>

Greetings! Apologies for the subject, I could not find a better way to summerize my question.

I'm using Kibana for analysis, and I have tried to create a visualization that shows the percentage of each HTTP method per domain, at each bucket of time.  
For example, let's say in domain "a[.]com" the traffic is 80% GET method and 20% POST, and in "b[.]org" it is 50%-50% at 12:00. I would love to see it in a visualization with 2 graphs (I only have GET and POST available) - one for each method, and within each graph see the percentage of the HTTP method for that domain.

I tried to do so by using split charts to the HTTP method and then split series for domain, however unfortunately the percentage calculation is wrong, as it calculates the percentage of each method against other domains and not against the other HTTP method within the specific domain:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/8/4879cd3e5bf0ca2271db35ffc426cfd46db6c61a.png)  
As you can see in this example, the pink bar has around 40% GET most of the time and 10% POST which doesn't make sense (as these are the only 2 options, other methods are not logged).

For example my current visualization can tell that

1. 'a[.]com' has 25% GET, 'b[.]org' has 75% GET
2. 'a[.]com' has 40% POST, 'b[.]org' has 60% GET  
The total percentage of 'a[.]com' is 65% which is not what I expect, because it calculates the percentage against the other domains and not against the other methods.

This is the query I believe:

```auto
"aggs": {
    "2": {
      "date_histogram": {
        "field": "@timestamp",
        "fixed_interval": "2m",
        "time_zone": "Asia/Jerusalem",
        "min_doc_count": 1
      },
      "aggs": {
        "3": {
          "terms": {
            "field": "http_method",
            "order": {
              "_count": "desc"
            },
            "size": 2
          },
          "aggs": {
            "4": {
              "terms": {
                "field": "domain",
                "order": {
                  "_count": "desc"
                },
                "size": 5
              }
            }
          }
        }
      }
    }
  }

```

---

<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 24, 2023, 8:40am UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153/2 "2023-05-24T08:40:40Z")

</div>

Hi @Halfon

welcome to the Kibana community.  
You can produce this type of chart with Lens, the only limit is to create two distinct panels instead of a split chart (small multiple is a feature not yet available in Lens).

Here's an example using `response.keyword: "200"` as filter:

 ![Screenshot 2023-05-24 at 10.36.52](https://us1.discourse-cdn.com/elastic/original/3X/0/6/06d01655b3c726979c43250ba367d4e1594b315f.png)

In the Kibana documentation there also other examples of ratio/percentage based charts with Lens: [Analyze time series data | Kibana Guide [8.7] | Elastic](https://www.elastic.co/guide/en/kibana/8.7/create-a-dashboard-of-panels-with-ecommerce-data.html#percentage-stacked-area)

---

<div class="post-metadata">

**Author:** ![Halfon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/halfon/32/121353_2.png) [@Halfon](https://discuss.elastic.co/u/Halfon)\
**Post date:** [May 24, 2023, 3:34pm UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153/3 "2023-05-24T15:34:34Z")

</div>

Thanks @Marco_Liberati !  
Unfortunately Lens doesn't seem to be available in my organization, and won't be in the near future ☹  
Is Lens the only option? We can't do it in the regular visualization?

---

<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:** [May 24, 2023, 3:39pm UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153/4 "2023-05-24T15:39:18Z")

</div>

Hi @Halfon Welcome to the community.

What version of the Elastic / Kibana are you on?

---

<div class="post-metadata">

**Author:** ![Halfon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/halfon/32/121353_2.png) [@Halfon](https://discuss.elastic.co/u/Halfon)\
**Post date:** [May 25, 2023, 9:42am UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153/5 "2023-05-25T09:42:29Z")

</div>

Hi @stephenb ,  
It appears to be 7.10.2 (based on a DevTools request to `/`).

---

<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:** [May 25, 2023, 3:55pm UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153/6 "2023-05-25T15:55:33Z")

</div>

@Halfon

The visualization capabilities have improved immensely since 7.10 as well as many many other improvements ... perhaps you should consider upgrading..

I got this to perhaps work but I don't have 7.10 to test on

Vertical Bar Chart

X-Axis Date Histogram  
Y Axis: Count  
Split Series: Terms : Respons Code  
Split Chart Rows: Tag (this would be your POST / GET)  
Axis: y-Axis Percentage

 ![Screenshot 2023-05-25 at 8.52.06 AM](https://us1.discourse-cdn.com/elastic/original/3X/0/8/08857b7ca8c94d3aed66779bcdfabc77be82e053.jpeg)

 ![Screenshot 2023-05-25 at 8.53.23 AM](https://us1.discourse-cdn.com/elastic/original/3X/c/4/c41fa746fe89227793de5ac39705a7bbf4bac87b.png)

 ![Screenshot 2023-05-25 at 8.52.19 AM](https://us1.discourse-cdn.com/elastic/original/3X/a/2/a27126dc1bd623aa0017b398657f6243e9bc7ad9.png)

The Chart is Broken into Rows yours would be POST / GET  
Each Row is a Percentile of the Response Code for the Row (POST / GET)

Best I could do 🙂

---

<div class="post-metadata">

**Author:** ![Halfon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/halfon/32/121353_2.png) [@Halfon](https://discuss.elastic.co/u/Halfon)\
**Post date:** [May 30, 2023, 11:08am UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153/7 "2023-05-30T11:08:59Z")

</div>

Thank you very much for all the effort @stephenb!  
Unfortunately it doesn't fit my needs as I need the metric count to be normal (instead of stacked) and the percentage to be calculated per domain and not against the other domains. I guess I will just have to find other solutions. But again thanks for all the effort!!

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

---

<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, 11:09am UTC](https://discuss.elastic.co/t/calculating-percentage-in-visualization-per-a-specific-field-and-not-the-regular-one/334153/8 "2023-06-27T11:09:31Z")

</div>

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