# How can I build verticalBar chart based on some custom calculation

**URL:** https://discuss.elastic.co/t/how-can-i-build-verticalbar-chart-based-on-some-custom-calculation/276964
**Category:** Kibana
**Created:** [June 24, 2021, 5:05pm UTC](https://discuss.elastic.co/t/how-can-i-build-verticalbar-chart-based-on-some-custom-calculation/276964 "2021-06-24T17:05:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![vivu007x](https://avatars.discourse-cdn.com/v4/letter/v/8dc957/32.png) [@vivu007x](https://discuss.elastic.co/u/vivu007x)
#### Post date: [June 24, 2021, 5:05pm UTC](https://discuss.elastic.co/t/how-can-i-build-verticalbar-chart-based-on-some-custom-calculation/276964/1 "2021-06-24T17:05:29Z")

</div>

Hi,  
I have created a VerticalBar chart in Kibana. I used the Metrics and Buckets option to choose the index and terms.

 ![Screen Shot 2021-06-24 at 9.57.37 AM](https://us1.discourse-cdn.com/elastic/original/3X/9/7/97170f2f27fe2675438083bec241c5fdee8df4e6.png)

Say,

totalValue is an index with values [available/offline/suspended]  
errorValue is an index with values [401/403/500]

I want my bars to be calculated on certain formula.  
e.g.  
((total available count of totalValue) - (total 401 count of errorValue) - (total 500 count of errorValue)) / ((total available count of totalValue) - (total 401 count of errorValue)) \* 100

Is it possible to build in kibana?

Thank you.

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [June 24, 2021, 5:23pm UTC](https://discuss.elastic.co/t/how-can-i-build-verticalbar-chart-based-on-some-custom-calculation/276964/2 "2021-06-24T17:23:06Z")

</div>

You can do this using a TSVB vertical bar chart with a Filter Ratio.

To use Lens, you can use [two filters aggregations like in this tutorial](https://www.elastic.co/guide/en/kibana/current/create-a-dashboard-of-panels-with-ecommerce-data.html#percentage-stacked-area). In the Vertical Bar chart you're using, you would also have to use 2 filter buckets.

We have also nearly finished work on a Lens Formula feature that will solve this problem, it might be released in Kibana, 7.14 or 7.15 depending on how testing goes.

---

<div class="post-metadata">

### Author: ![vivu007x](https://avatars.discourse-cdn.com/v4/letter/v/8dc957/32.png) [@vivu007x](https://discuss.elastic.co/u/vivu007x)
#### Post date: [June 25, 2021, 11:08pm UTC](https://discuss.elastic.co/t/how-can-i-build-verticalbar-chart-based-on-some-custom-calculation/276964/3 "2021-06-25T23:08:55Z")

</div>

Thanks Wylie.

I am going with the TSVB option by following the initial steps mentioned in [Filter ratio in TSVB](https://discuss.elastic.co/t/filter-ratio-in-tsvb/244842).

I am trying to perform a sum operation on one of the fields but I do not see that field as an option. I used python to create mapping and later dumping the data using the API.

```auto
 "mappings": {
            "properties": {
                "timestamp": {
                    "type": "date"
                },
                "status": {
                    "type": "text",
                    "fields": {
                        "raw": {
                            "type": "keyword"
                        }
                    }
                },
                "service": {
                    "type": "text",
                    "fields": {
                        "raw": {
                            "type": "keyword"
                        }
                    }
                }
            }
        }

```

I can only see epoch\_time in the dropdown. Is it because that's the only integer field? How would I make a sum aggregation on a string field like 'service'. Is my mapping correct?

 ![Screen Shot 2021-06-25 at 4.05.15 PM](https://us1.discourse-cdn.com/elastic/original/3X/5/d/5d7c5fa2be6b8b88cda2315292af82a18d2d05ef.png)

---

<div class="post-metadata">

### Author: ![vivu007x](https://avatars.discourse-cdn.com/v4/letter/v/8dc957/32.png) [@vivu007x](https://discuss.elastic.co/u/vivu007x)
#### Post date: [June 28, 2021, 5:42am UTC](https://discuss.elastic.co/t/how-can-i-build-verticalbar-chart-based-on-some-custom-calculation/276964/4 "2021-06-28T05:42:03Z")

</div>

Hi,  
I added a scripted field as integer which I can see in discovery tab.  
Now when I goto visualization -\> TSVB and select my index, under data -\> Aggregation-\> Sum , I don't see the scripted field option there. I want to add a sum field on scripted field and do a bucket aggregation to find the percentage.  
How can I get the scripted field there?

---

<div class="post-metadata">

### Author: ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)
#### Post date: [June 28, 2021, 2:38pm UTC](https://discuss.elastic.co/t/how-can-i-build-verticalbar-chart-based-on-some-custom-calculation/276964/5 "2021-06-28T14:38:13Z")

</div>

TSVB does not allow you to take the sum of a scripted field, although you can use these scripted fields with KQL. Starting in 7.13.0 TSVB does support [ES runtime fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html) and [Kibana runtime fields](https://www.elastic.co/guide/en/kibana/current/managing-index-patterns.html).

---

<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: [July 26, 2021, 2:38pm UTC](https://discuss.elastic.co/t/how-can-i-build-verticalbar-chart-based-on-some-custom-calculation/276964/6 "2021-07-26T14:38:17Z")

</div>

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