Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Congratulations to the new Qlik Luminary and Partner Ambassador class! Meet them here
cancel
Showing results for 
Search instead for 
Did you mean: 
NenadV
Creator II
Creator II

How to convert Month names to numbers to get a proper sort order in a YearMonth field?

For example

Month Year
January 2026
February 2026
March 2026
April 2026
May 2026
June 2026
July 2026
August 2026

Year &'-'& Month  as YearMonth is not sorted good enough as text, but 2026-1, 2026-2, etc.  sorted as text would be acceptable .

I am sure there is more elegant solution available than this rudimentary one:

Year &'-'& dual(Month, if(Month= 'January',1,if(Month= 'February',2,if(Month= 'March',3,if(Month= 'April',4,if(Month= 'May',5,if(Month= 'June',6,if(Month= 'July',7,if(Month= 'August',8,if(Month= 'September',9,if(Month= 'October',10,if(Month= 'November',11,if(Month= 'December',12,0))))))))))))) as YearMonth,

Thanks

Labels (3)
1 Solution

Accepted Solutions
Chanty4u
MVP
MVP

Hi

If your Month field contains values like "January", "February", etc., you can use

Year & '-' & Num(Month(Date#(Month, 'MMMM')), '00') as YearMonth

 

text sorting also gives the correct chronological order.

 

Or try this 

If you want to display January 2026 but sort it chronologically, I'd recommend creating a proper date/dual field:

Date(MakeDate(Year, Month(Date#(Month, 'MMMM'))), 'MMMM YYYY') as MonthYear

Then you can sort MonthYear numerically while displaying:

View solution in original post

3 Replies
Chanty4u
MVP
MVP

Hi

If your Month field contains values like "January", "February", etc., you can use

Year & '-' & Num(Month(Date#(Month, 'MMMM')), '00') as YearMonth

 

text sorting also gives the correct chronological order.

 

Or try this 

If you want to display January 2026 but sort it chronologically, I'd recommend creating a proper date/dual field:

Date(MakeDate(Year, Month(Date#(Month, 'MMMM'))), 'MMMM YYYY') as MonthYear

Then you can sort MonthYear numerically while displaying:

NenadV
Creator II
Creator II
Author

Yes. The 2nd option is perfect.

Thank you Chanty

Chanty4u
MVP
MVP

Glad it worked ! Happy weekend 🙂