# To sort the values appearing on a date dropdown in descending order

**URL:** <https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823>\
**Category:** Q&A\
**Tags:** analysis, formulas, filters, calculations, Business-Intelligence-Engineer, quick-sight\
**Created:** [June 3, 2024, 5:52am UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823 "2024-06-03T05:52:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ganga](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@Ganga](https://community.amazonquick.com/u/Ganga)\
**Post date:** [June 3, 2024, 5:52am UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/1 "2024-06-03T05:52:19Z")

</div>

I have created a date dropdown control, based on the requirement  
 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/3X/c/7/c72eb51404b6816c4d662ad06dd837d1ac3d710d.png)

Since we don’t have any option to display this in descending order, I need to attach some prefix to display the latest date first. I am attaching my Report month calculation here, How can I add a prefix to this report month so that the dates will appear in descending order using quick sight calculation?

These are the calculations I am using to calculate report month (string datatype).

Year =toString(extract(‘YYYY’,{report\_date}))  
Month= extract(‘MM’,{report\_date})  
MM=ifelse(Month=1,‘01’,  
Month=2,‘02’,  
Month=3,‘03’,  
Month=4,‘04’,  
Month=5,‘05’,  
Month=6,‘06’,  
Month=7,‘07’,  
Month=8,‘08’,  
Month=9,‘09’,  
Month=10,‘10’,  
Month=11,‘11’,‘12’)

Report Month= concat(Year,‘-’,MM)

Please help to attach a prefix to this from quicksight side, so that I can display the Report months in descending order

---

<div class="post-metadata">

**Author:** ![WLS-DM](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/wls-dm/32/36109_2.png) [@WLS-DM](https://community.amazonquick.com/u/WLS-DM)\
**Post date:** [June 4, 2024, 5:35pm UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/2 "2024-06-04T17:35:36Z")

</div>

Hello @Ganga, I was able to write out some calculated fields to make this work! We can use a denseRank calculation to rank the dates by month descending. That will be how we control the value added in front. To build that, I also created a calculated field to convert the date value to a month.

Date Month = `truncDate('MM', {report_date})`

Rank Dates =

```auto
denseRank
(
  [{Date Month} DESC], 
  [],
  PRE_AGG
)

```

Report Month =

```auto
concat(
ifelse({Rank Dates} <= 9, 
concat('0', toString({Rank Dates})),
toString({Rank Dates})),
': ',
toString(extract('YYYY',{report_date})),
'-', 
ifelse(strlen(toString(extract('MM',{report_date}))) = 1, 
concat('0', toString(extract('MM',{report_date}))), 
toString(extract('MM', {report_date}))))

```

These 3 calculations should provide the result you are looking for! I will mark my response as the solution, but let me know if you have any questions. Thank you!

---

<div class="post-metadata">

**Author:** ![Ganga](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@Ganga](https://community.amazonquick.com/u/Ganga)\
**Post date:** [June 5, 2024, 5:29am UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/3 "2024-06-05T05:29:36Z")

</div>

HI @WLS-DM ,

Thankyou So much for the response. I tried with this calculations, and I was able to achieve this as a field. But while trying to pull this to controls I am getting error msg showing that to make as a custom filter and if we make that we have to explicitly specify the values. Is there any way to resolve this, so that we can directly use that Report Month field as normal control?

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/3X/e/6/e6b3bb177453cd127081641ec31cfb26cf657113.png)

---

<div class="post-metadata">

**Author:** ![WLS-DM](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/wls-dm/32/36109_2.png) [@WLS-DM](https://community.amazonquick.com/u/WLS-DM)\
**Post date:** [June 5, 2024, 3:04pm UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/4 "2024-06-05T15:04:39Z")

</div>

Hello @Ganga, I wonder if it would bypass this issue if you built the calculated field on the dataset, then used a parameter based control to populate the list from the dataset and liked it to a filter that way.

---

<div class="post-metadata">

**Author:** ![Ganga](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@Ganga](https://community.amazonquick.com/u/Ganga)\
**Post date:** [June 6, 2024, 9:42am UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/5 "2024-06-06T09:42:10Z")

</div>

Hi @WLS-DM ,

Thanks For your suggestion, I have created the same calculations at dataset level and tried the same, and in report created a parameter to link this . But still the same error i am getting. If i display this in visuals, its populating, but controls is still showing this error

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/3X/8/b/8b3c6c91b687a3f169fe17e3a0cf30bb9eab5feb.png)

---

<div class="post-metadata">

**Author:** ![WLS-DM](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/wls-dm/32/36109_2.png) [@WLS-DM](https://community.amazonquick.com/u/WLS-DM)\
**Post date:** [June 11, 2024, 10:11pm UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/6 "2024-06-11T22:11:00Z")

</div>

Hello @Ganga, I am wondering if it is because we are using the denseRank calculation and it is overcomplicating the field. That is the only thing I can think of that might be causing you to run into this limitation.

Are you utilizing any custom SQL, whether in Quick Sight or in your database, where you could set the rank values ahead of time? Maybe if we can reduce the number of calculations leading into the final field, we can get it to run correctly.

---

<div class="post-metadata">

**Author:** ![Ganga](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@Ganga](https://community.amazonquick.com/u/Ganga)\
**Post date:** [June 13, 2024, 1:53pm UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/7 "2024-06-13T13:53:45Z")

</div>

I have solved it by adding the prefix from database side. Thanks!

---

<div class="post-metadata">

**Author:** ![WLS-DM](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/wls-dm/32/36109_2.png) [@WLS-DM](https://community.amazonquick.com/u/WLS-DM)\
**Post date:** [June 14, 2024, 4:12pm UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/8 "2024-06-14T16:12:39Z")

</div>

Hello @Ganga, thank you for letting me know! I wish I fully understood why the original function didn’t work, but it just seems like we hit a limitation. Updating the query is always an option to manage some of these custom field updates.

---

<div class="post-metadata">

**Author:** ![Xclipse](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/xclipse/32/20455_2.png) [@Xclipse](https://community.amazonquick.com/u/Xclipse)\
**Post date:** [June 15, 2024, 12:56am UTC](https://community.amazonquick.com/t/to-sort-the-values-appearing-on-a-date-dropdown-in-descending-order/30823/9 "2024-06-15T00:56:30Z")

</div>

Archived on June 15, 2024, 12:56am UTC


