Sort Month Name

Hi!

I would like to find out if there’s any way to sort month name according to month order (Jan, Feb, Mar, Apr, …) instead of alphabetical order (Apr, Feb, Jan, Mar, …)?

Thank you!

@App_Creator
May I ask where and how you are using that month names? And how you get them? With long date setting? Please elaborate.

Thanks LeventK.

I got the month names using switch expression and the names became Text. Hence sorting according to alphabetical order.

SWITCH(MONTH([Date]), 1, “Jan”, 2, “Feb”, 3, “Mar”, 4, “Apr”, 5, “May”, 6, “Jun”, 7, “Jul”, 8, “Aug”, 9, “Sep”, 10, “Oct”, 11, “Nov”, “Dec”)

I am using these month names to group a set of entries and sort in desending order according to the month in a table view.

Thank you!

@App_Creator
If it’s not a big deal for you, slightly change your SWITCH expression:

SWITCH(
MONTH([Date]),
1, “1-Jan”,
2, “2-Feb”,
3, “3-Mar”,
4, “4-Apr”,
5, “5-May”,
6, “6-Jun”,
7, “7-Jul”,
8, “8-Aug”,
9, “9-Sep”,
10, “10-Oct”,
11, “11-Nov”,
“12-Dec”
)

2 Likes

That’s a great workaround! I will use that for the time being.

Thanks for your help, Leventk!

You’re welcome @App_Creator, my pleasure. Great to be helped of.

@LeventK

Any idea why the results are formatted as timedate with this solution? The date column this expression refers to is formatted as a date column yet the results of the SWITCH expression are formatted as timedate?

What happens if you change your column type to text?

1 Like

@Michael
That’s basically because AppSheet interprets “1-JAN” string as a short format Joda Date and appends 12:00:00AM to it and therefore evaluates the string as “1st of January 12:00:00AM”, “2nd of February 12:00:00AM”, “3rd of March 12:00:00AM” and so on. As @Aleksi mentioned check the type of your Virtual Column and change it to Text if not.

2 Likes

@Aleksi Although I have changed the date column to be formatted as text: TEXT(DATE([TimeStamp])), the result is still formatted as a date and therefore the SWITCH expression still results as timedate. The switch expression column is also formatted as text.
@LeventK

I’m still struggling with the idea that there has to be a way to display just the name of the month (without the preceding number and hyphen) and still have it sorted by month. Can anyone think of a way to “alias” a VC? Some sort of sort by “this” but display “that”? This is an old thread, has this been solved somewhere else?

“This” would be a Ref value and “that” would be its label.

Yeah. I was thinking that Ref might be the way to go but then if i’m using the label in any other view that will throw that off. I’m still wrapping my head around all of the possibilities with Ref/Labels. I’ve probably overbuilt this particular table and am trying to do too much with it. Should build in more smaller Ref tables. I’ll keep at it and see what I can figure out. Thanks for the reply!

1 Like

This is a perfect example of when a read-only table is appropriate.
[ID] is your key column, with 1-12.
[Month] is your text label column.

I do this exactly but for day of the week, and for the exact same reason.

1 Like