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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Making a Year Month Column


Hello, please can someone tell me how to make a year month column

I am bringing in a field from excel called Anticipated Launch date.

An example of a date being brought in is Apr-15

I want to create a new column with year month in it so would want the above to show as

2015-4

Please can someone help with this issue.

Thank you

Kind Regards

13 Replies
Not applicable
Author


Unfortunately this is still not working

Anonymous
Not applicable
Author

Emma

What kind of not working ?

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

It seems you have two date formats in your data source. Use the Alt() statement to parse the date in two or more formats, like this:

Date(Alt(Date#([Launch Date],'MMM-YY'), Date#([Launch Date],'YYYY-M')),'YYYY-M') as YearMonth

The first Date# will match the MMM-YY fields, but the YYYY-M fields in your input will not match, so then the Alt() will try the second Date#. The Date() statement will ensure all the resulting dates display as YYYY-M.

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
MarcoWedel

either:

LOAD

  Date(Date#(yearmonth ,'YYYY-M'),'YYYY-M') as yearmonth;

SQL SELECT

  convert(varchar,year([PstngDate])) + '-' +  convert(varchar,month([PstngDate])) as yearmonth

FROM yourdatabase;

or:

LOAD

  Date(PstngDate,'YYYY-M') as yearmonth;

SQL SELECT

  PstngDate

FROM yourdatabase;