# Is there a way to use expressions when doing aggregations (using Datatable)?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-use-expressions-when-doing-aggregations-using-datatable/66789>\
**Category:** Kibana\
**Created:** [November 21, 2016, 9:53pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-expressions-when-doing-aggregations-using-datatable/66789 "2016-11-21T21:53:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![linuxdev](https://avatars.discourse-cdn.com/v4/letter/l/a88e57/32.png) [@linuxdev](https://discuss.elastic.co/u/linuxdev)\
**Post date:** [November 21, 2016, 9:53pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-expressions-when-doing-aggregations-using-datatable/66789/1 "2016-11-21T21:53:42Z")

</div>

Hi

So do a count aggregation over terms with resuts looking like this:

```
term1 345
term2 249
term3 117

```

I would like to show a second column that would represent a percentage of total count, ex:

```
term1 345 3.45%
term2 249 2.47%
term3 117 2.22%

```

Does Kibana support something like this?  
Can I do something like this for example?

```
{ "script" : "doc['word'].count/(TOTAL/100)" }
```

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [November 22, 2016, 11:05pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-expressions-when-doing-aggregations-using-datatable/66789/2 "2016-11-22T23:05:11Z")

</div>

Currently, no, that's not something Kibana does out of the box, and I don't think that the Lucene query language allows you to get the total. I think the reason is that it's not something Elasticsearch does, and we have historically tried not to add features in Kibana that we can't do in Elasticsearch, though I think that mindset is changing.

I'm pretty confident that pipeline aggs would allow you to do this pretty easily, but Kibana currently doesn't provide any way to use them.

It's also possible that the new [Painless scripting language](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-painless.html) in Elasticsearch will allow this, but I'm not really familiar with it myself, so you'd have to flip through the docs yourself to see if that's right.

Also, here's an issue in the Kibana repo to track this: [https://github.com/elastic/kibana/issues/4528](https://github.com/elastic/kibana/issues/4528)

---

<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:** [December 20, 2016, 11:05pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-expressions-when-doing-aggregations-using-datatable/66789/3 "2016-12-20T23:05:26Z")

</div>

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