# Counting the last element of each aggregation

**URL:** https://discuss.elastic.co/t/counting-the-last-element-of-each-aggregation/115865
**Category:** Kibana
**Created:** [January 17, 2018, 10:51am UTC](https://discuss.elastic.co/t/counting-the-last-element-of-each-aggregation/115865 "2018-01-17T10:51:27Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Tomas\_Law](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@Tomas\_Law](https://discuss.elastic.co/u/Tomas_Law)
#### Post date: [January 19, 2018, 3:54pm UTC](https://discuss.elastic.co/t/counting-the-last-element-of-each-aggregation/115865/6 "2018-01-19T15:54:37Z")

</div>

Hey Lukas,

The solution you proposed does get me the list of all of the last cs\_uris for each session\_id.

I've come up with a (better but not complete) solution where I manage to get the count split by tables but I can't order them.

The link to the post with the split table aggregation is:

> [@Data Table with split table ordering](https://discuss.elastic.co/t/data-table-with-split-table-ordering/116030):
>
> Hello, After a couple split rows and split tables aggregations I get the following result: The most important metric I get comes from the Total function in the visualization Options which is the Sum (circled in red). I want to order the splitted tables according to the sum value (left: highest sum- \>right: lowest sum) but I don't know how to use this Sum value to order them. [image] How can I do it? Thank you

Thanks for replying!

---

_[View the full topic](https://discuss.elastic.co/t/counting-the-last-element-of-each-aggregation/115865)._
