Sorting months based on chronological order

Certified Senior Developer

Hi All,

I am having a list of months shuffled in a list. I want to arrange them in their chronological order. But I can sort only on alphabetical order. Help me guys.

local!months:{"June","January","March","Novemeber","February","October","December","April","July","May","September","August"},
sort(local!months).

Thank you

  Discussion posts and replies are publicly visible

Parents Reply
  • Well, assuming you start off with a passed-in, randomized list of month names in a text array, and nothing else, here is what i'd suggest, just off the top of my head:

    First, loop over the list of months using a!forEach().  The output of this loop will need to be slightly different dependent on whether we expect it to possibly handle duplicated months.  In the loop, compare the month name to a predefined list.  The output should be a dictionary or map containing a "name" parameter with the current item name in the loop, then a "number" parameter with the month's integer number in a calendar year (1 - 12).

    After that, you should be able to use our standard trick for sorting a dictionary by the value of a particular parameter, sorting by the "number" parameter in this case - utilizing the toDataSubset() function (i believe someone posted the approximate code for this up-thread).

Children