# Display percentage based on parent aggregation doc\_count

**URL:** <https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370>\
**Category:** Kibana\
**Created:** [February 28, 2019, 3:17pm UTC](https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370 "2019-02-28T15:17:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![punppis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/punppis/32/46041_2.png) [@punppis](https://discuss.elastic.co/u/punppis)\
**Post date:** [February 28, 2019, 3:17pm UTC](https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370/1 "2019-02-28T15:17:10Z")

</div>

I have a query for daily login retention, which gets sub-buckets (by term filter) of each day (date histogram). Instead of absolute values, I would like to know percentage of each sub-bucket to the parent bucket count.

I would like to calculate the sub-buckets doc\_count / parent buckets doc\_count \* 100, so percentage of total rows. So If i have a doc\_count of 3 before the filter and three sub-buckets with doc\_counts of 1, 2 and 3 respectively I should get 33%, 66% and 100% values to be shown in the graph.

query: [https://pastebin.com/raw/ZREkj2na](https://pastebin.com/raw/ZREkj2na)  
results: [https://pastebin.com/raw/ucsTF2np](https://pastebin.com/raw/ucsTF2np)

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 6, 2019, 10:13am UTC](https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370/2 "2019-03-06T10:13:35Z")

</div>

Hi,

If you are using the standard visualization editor, you can configure this by setting the "Mode" of the y axis to "percentage" in the "Metrics & Axes" tab on the left side (second dropdown from the bottom in the screenshot):

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

---

<div class="post-metadata">

**Author:** ![punppis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/punppis/32/46041_2.png) [@punppis](https://discuss.elastic.co/u/punppis)\
**Post date:** [March 13, 2019, 9:22am UTC](https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370/3 "2019-03-13T09:22:25Z")

</div>

This is not working as exptected. It calculates percentage against total sum of sibling buckets (sum is always 100) and I need a percentage against the total parent doc\_count.

Example bucket:

- doc\_count (100, total of users)
- 
  - iphone\_users (10, total of users with iphone). this should be 10%

- 
  - android\_users (55, total of users with android). this should be 55%

Your example would give a percentages of 15,38% and 84,62%. Should be 10% and 55%.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 13, 2019, 12:29pm UTC](https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370/4 "2019-03-13T12:29:40Z")

</div>

If you enable the "Group other values in separate bucket" in the split series configuration, you should get the numbers you want.  
 ![55](https://us1.discourse-cdn.com/elastic/original/3X/6/b/6b8a1a64b992b978dfb70c692b5a9dfb11f601e5.png)

---

<div class="post-metadata">

**Author:** ![punppis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/punppis/32/46041_2.png) [@punppis](https://discuss.elastic.co/u/punppis)\
**Post date:** [March 14, 2019, 12:38pm UTC](https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370/5 "2019-03-14T12:38:43Z")

</div>

Still shows all sub-buckets as total of 100% (no change)

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 14, 2019, 9:53pm UTC](https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370/6 "2019-03-14T21:53:48Z")

</div>

Each column will still add up to 100%, but this setting should add a separate label "Other" - so in your example you should have iphone\_users 10%, android\_users 55% and Other 35%

Like in the screenshot - everything adds up to 100%, but the percentages are calculated correctly for the two "named buckets", in this case "IN" and "CN"  
Without Other bucket:

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

With Other bucket:

 ![58](https://us1.discourse-cdn.com/elastic/original/3X/e/5/e530677871fb463025215b4ad7443890064c8a19.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:** [April 11, 2019, 9:56pm UTC](https://discuss.elastic.co/t/display-percentage-based-on-parent-aggregation-doc-count/170370/7 "2019-04-11T21:56:51Z")

</div>

Closed on April 11, 2019, 9:56pm UTC

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