The sort order of text data field in filter

In my dataset,I have a field which has Month name stored as Text datatype, in the custom SQL query I have applied order by function and the month names are in ascending order only but in the filter the month names are not in ascending order

Hi @Tanu_13

When you have a field storing the month name as a text datatype, Quick Sight filter controls will typically sort these month names alphabetically, not chronologically (i.e., January to December), even if your underlying SQL query uses an ORDER BY clause. The filter UI does not respect the SQL order because it handles text fields using default alphanumeric sorting.

To have the months appear in chronological order (January, February, … December) in filters and visuals, you need to create a custom sort column that represents the natural month order. In your visual or filter setup, sort by this new month number field, not by the month name text.

Example:

ifelse(
  {Month}='January',1,
  {Month}='February',2,
  {Month}='March',3,
  {Month}='April',4,
  {Month}='May',5,
  {Month}='June',6,
  {Month}='July',7,
  {Month}='August',8,
  {Month}='September',9,
  {Month}='October',10,
  {Month}='November',11,
  {Month}='December',12,0
)

Thnks for replying @Xclipse , can you please elaborate a bit where to use above if condition

Hi @Tanu_13

Create the calculated field using ifelse, and use this field for sorting in your visuals and filter controls to display months chronologically, not alphabetically.

Please refer the below community post this might be helpful for you.

Hi @Tanu_13

It’s been a while since we last heard from you. If you have any further questions, please let us know how we can assist you.

If we don’t hear back within the next 3 business days, we’ll proceed with close/archive this topic.

Thank you!

Hi @Tanu_13

Since we have not heard back from you, I’ll go ahead and close/archive this topic. However, if you have any additional questions, feel free to create a new topic in the community and link this discussion for relevant information.

Thank you!