Qlik Community

Ask a Question

QlikView Administration

Discussion Board for collaboration on QlikView Management.

Announcements
Our next Qlik Insider session will cover new key capabilities. Join us August 11th REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
clemmytang
Contributor III
Contributor III

Create YYYYMM and Year field in script from a date field

Hi,

I have a field in my script called "Ordering_Date", the format of this column is set as a date (see attached image). I would like to create another field that essentially is a column that captures just the year and month, in the format "YYYMM" from the Ordering_Date field  as well as a column that captures just the year. Would this be a convert formula? What should I add to my script to load those two requested columns?

Please advise.

 

Thanks in advance,

Clem

1 Solution

Accepted Solutions
JuanGerardo
Partner
Partner

OK, I see the problem. You have two sections, the SQL part that runs the query against your Oracle database, and the LOAD part that tells Qlik what to do with those query results. This sentences must be included in the LOAD part as they are Qlik functions, something like this:

LOAD
   *,
   Date(MonthStart(ORDERING_DATE), 'YYYMM') AS Ordering_Month,
   Year(ORDERING_DATE) AS Ordering_Year
;
SELECT ....
FROM ...
;

And don't forget to remove those lines from the SQL sentence, as Oracle doesn't understand the Qlik functions.

JG

View solution in original post

6 Replies
JuanGerardo
Partner
Partner

Try this:

Date(MonthStart(Ordering_Date), 'YYYMM') AS Ordering_Month,
Year(Ordering_Date) AS Ordering_Year

JG

clemmytang
Contributor III
Contributor III
Author

Thanks for your reply. I added your suggestion to my script:clemmytang_0-1624373303303.png

Didn't work 😞 I got the following error:

clemmytang_1-1624373433101.png

 

JuanGerardo
Partner
Partner

You must use the source field: PROC.ORDERING_DATE

JG

clemmytang
Contributor III
Contributor III
Author

Hi  JG,

 

I tried that as well and it still did not work 😞

JuanGerardo
Partner
Partner

OK, I see the problem. You have two sections, the SQL part that runs the query against your Oracle database, and the LOAD part that tells Qlik what to do with those query results. This sentences must be included in the LOAD part as they are Qlik functions, something like this:

LOAD
   *,
   Date(MonthStart(ORDERING_DATE), 'YYYMM') AS Ordering_Month,
   Year(ORDERING_DATE) AS Ordering_Year
;
SELECT ....
FROM ...
;

And don't forget to remove those lines from the SQL sentence, as Oracle doesn't understand the Qlik functions.

JG

View solution in original post

clemmytang
Contributor III
Contributor III
Author

JG, you are a genius 🙂 Your suggestion worked.

 

Thank you so much!!

Clem