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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Getting Month and Year Fields from a Single Date Field

Hi everyone I just started learning Qlikview for an internship. Right now I have an Excel spreadsheet with a Column of dates (OrderDate). However, in my Qlikview application I need to make selections based on Month and Year.

Currently, in my Month and Year tables, I'm using the expressions Month(OrderDate) and Year(OrderDate) respectively. This works, but I also have a Current Selections box in my application and since neither the Month or the Year are fields, making a selection in either of the boxes only shows up as an OrderDate Field with a Value of somthing like 32 of 548.

I have a completed example as a reference and in that example, making a selection in either the Month or Year boxes shows up as the Month or Year field in the Current Selections box, and has a value of Jan, Feb, ...etc and 2005,2006,...etc.

Any help would be appreciated.

Thanks, Yiling

1 Solution

Accepted Solutions
Not applicable
Author

In that case you might want to simply change your script to read something like

SQL SELECT *, Month(OrderDate,'MMM') As OrderMonth, Year(OrderDate,'YYYY') AS OrderYear FROM...........

Regards,

Nigel.

View solution in original post

5 Replies
Not applicable
Author

Hello Yiling

You should probably create these fields in your load script, at the moment you probably have something like:

LOAD OrderDate FROM xxxxx.XLS

You should change this so that you have:

LOAD OrderDate, MONTH(OrderDate, 'MMM') AS OrderMonth, YEAR(OrderDate,'YYYY') AS OrderYear FROM xxxx.XLS

This should make them separate fields.

Good luck,

Nigel.

Not applicable
Author

Hi Nigel,

Thanks for the quick reply.

Currently my script looks like:

ODBC CONNECT TO [Excel Files;DBQ=C:\...\Sales.xls];
SQL SELECT *
FROM `C:\...\Sales.xls`.`Customers$`;

SQL SELECT *
FROM `C:\...\Sales.xls`.`Orders$`;

where Customers and Orders are two different tables within the Sales.xls document. I know that the SQL Select * means its reading all the fields from the table, but I never use LOAD anywhere. How would I change this?

Thanks again,

Yiling

Not applicable
Author

In that case you might want to simply change your script to read something like

SQL SELECT *, Month(OrderDate,'MMM') As OrderMonth, Year(OrderDate,'YYYY') AS OrderYear FROM...........

Regards,

Nigel.

Not applicable
Author

Worked like a charm!

Thanks!

Not applicable
Author

Just one little thing though.

The Month function only takes one argument so you can't load it and format it all at once.

But thanks again!

Yiling