# How to show last n records in ascending order in kibana dashboard

**URL:** <https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323>\
**Category:** Kibana\
**Created:** [December 2, 2020, 8:42am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323 "2020-12-02T08:42:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajain16](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@ajain16](https://discuss.elastic.co/u/ajain16)\
**Post date:** [December 2, 2020, 8:42am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/1 "2020-12-02T08:42:07Z")

</div>

Hi All,

We have data and time field in X axis and we are showing data on X axis from today to today+25 records. e.g 3Dec, 2 Dec, 1 Dec, 30 Nov, 29 Nov etc.  
We need to show total 25 data count in reverse order.  
e.g 25 Nov, 26 Nov,27 Nov, 28 Nov, ....... 2 Dec, 3 Dec, 4Dec.

Could you please suggest any solution for the same?

---

<div class="post-metadata">

**Author:** ![dosant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dosant/32/64489_2.png) [@dosant](https://discuss.elastic.co/u/dosant)\
**Post date:** [December 3, 2020, 4:43pm UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/2 "2020-12-03T16:43:34Z")

</div>

Hi @ajain16,

What visualization type are you using?  
Could you please give a bit more input? A screenshot would help.

I am a bit confused, because by default any date-histogram on x-axis uses ascending order.

---

<div class="post-metadata">

**Author:** ![ajain16](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@ajain16](https://discuss.elastic.co/u/ajain16)\
**Post date:** [December 4, 2020, 4:59am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/3 "2020-12-04T04:59:29Z")

</div>

Hi Dosant,

Please find below snapshot of Descending and Ascending order.  
We want to see data from today to last 25 records (e.g 4 Dec to 25th Nov ). Current we are unable to achieve the same using ascending order.  
Please suggest me if there any changes is required.

Descending order:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/4/94e2dd2ab2191c12be29ac9261884a713dff459c.png)

Ascending order

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/6/1603619777c3bfdeafd3713ac50a3cfcf3938a76.png)

---

<div class="post-metadata">

**Author:** ![dosant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dosant/32/64489_2.png) [@dosant](https://discuss.elastic.co/u/dosant)\
**Post date:** [December 4, 2020, 10:16am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/4 "2020-12-04T10:16:52Z")

</div>

Instead of using terms aggregation on x-axis and alphabetical sorting, I'd suggest to use date-histogram aggregation. For this your `field` should be a timestamp instead of formatted date string.

Example:

 ![Screenshot 2020-12-04 at 11.16.11](https://us1.discourse-cdn.com/elastic/original/3X/8/d/8d79f7420a15af60672a1de084f39aaddcffe21d.png)

As you can see, with this you'd get a desired result on x-axis.

---

<div class="post-metadata">

**Author:** ![ajain16](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@ajain16](https://discuss.elastic.co/u/ajain16)\
**Post date:** [December 7, 2020, 7:50am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/5 "2020-12-07T07:50:59Z")

</div>

@dosant - If I used data histogram then I am unable to see time on X axis. In additional to this it was not showing all the dates. Please refer below snapshot.  
Do you have any solution for the problem.?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/1/5195b051a8e29590d3874517f9f39155fba66a34.png)

---

<div class="post-metadata">

**Author:** ![dosant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dosant/32/64489_2.png) [@dosant](https://discuss.elastic.co/u/dosant)\
**Post date:** [December 7, 2020, 10:53am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/6 "2020-12-07T10:53:01Z")

</div>

So your requirement is to display exact data and time per bar on x-axis? Then indeed I think data-histogram wouldn't work and terms seems more appropriate ☹

Maybe you can change formatting of your `start` string such that alpabetical sorting matches time sorting?  
e.g.:

- 2020-11-04 | 05:00
- 2020-11-05 | 06:00
- 2020-12-04 | 18:00

---

<div class="post-metadata">

**Author:** ![ajain16](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@ajain16](https://discuss.elastic.co/u/ajain16)\
**Post date:** [December 8, 2020, 8:21am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/7 "2020-12-08T08:21:18Z")

</div>

@dosant - We already have tried with the alphabetical sorting. But still it is not working.

---

<div class="post-metadata">

**Author:** ![dosant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dosant/32/64489_2.png) [@dosant](https://discuss.elastic.co/u/dosant)\
**Post date:** [December 8, 2020, 10:49am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/8 "2020-12-08T10:49:22Z")

</div>

> [@ajain16](#):
>
> We want to see data from today to last 25 records (e.g 4 Dec to 25th Nov ). Current we are unable to achieve the same using ascending order.

What if you'd also setup a time range filter to filter on a specific time interval (to get last ~25 records)

![Screenshot 2020-12-08 at 11.27.11](https://us1.discourse-cdn.com/elastic/original/3X/6/8/68796cce4fe77a85d86fa6736bcfb733abb45258.png)

This filter will be saved with your visualization and will be applied when viz is used on a dashboard.

---

<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:** [January 5, 2021, 10:49am UTC](https://discuss.elastic.co/t/how-to-show-last-n-records-in-ascending-order-in-kibana-dashboard/257323/9 "2021-01-05T10:49:23Z")

</div>

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