Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
dunnalahk123
Creator III
Creator III

Derive month number in QS

Hi,

 

can some one guide me how can we derive the month number 

 

example : I have value as August 2023 in one month field from that i want to derive value as just "8" which is august  month number.

1 Solution

Accepted Solutions
daturpin
Partner - Creator II
Partner - Creator II

I am not sure...  But try:

text(Num(Month(Date#(MonthYear, 'MMMM, YYYY'))),'00')

Which...  should store the value as a string with a preceding zero if less than 10?

View solution in original post

8 Replies
BrunPierre
Partner - Master
Partner - Master

Num(Month(Date#(MonthYear, 'MMMM YYYY'))) as MonthNumber

daturpin
Partner - Creator II
Partner - Creator II

In an expression, if the column is already a time, just use

=Num(Month(your_variable))

dunnalahk123
Creator III
Creator III
Author

Thank you, I am not getting any values, may be is it due to comma in my values? 

Num(Month(Date#(Start_Month_and_year, 'MMMM YYYY')))

dunnalahk123_0-1692712713082.png

 

daturpin
Partner - Creator II
Partner - Creator II

That's just a different format. Try adding the comma:

Num(Month(Date#(MonthYear, 'MMMM, YYYY'))) as MonthNumber

dunnalahk123
Creator III
Creator III
Author

Hi,

 

Thank you so much , right now i am getting what i need.   can we get "04" instead of 4  i mean from jan to sep i am getting like single number like 1 , 2 ,3  instead of that i need like 01, 02, 03,04 for Jan, feb, march , april.

 

again from Oct, nov, dec  we are ok. we are getting double digit.

 

dunnalahk123_0-1692718549030.png

 

daturpin
Partner - Creator II
Partner - Creator II

I am not sure...  But try:

text(Num(Month(Date#(MonthYear, 'MMMM, YYYY'))),'00')

Which...  should store the value as a string with a preceding zero if less than 10?

Or
MVP
MVP

In cases like this, I'd typically advise you just spell out the options using Pick(Match()) and not work so hard to do it using date functions. It's not as "clean" but it works and it's quick.

Pick(WildMatch(DateField,'January*','February*'),'01','02')

 

BrunPierre
Partner - Master
Partner - Master

Num(Month(Date#(MonthField, 'MMMM, YYYY')),'00') as MonthNumber