Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
tracycrown
Creator III
Creator III

Change Date format

Dear Sir/Madam

Kindly advise how to convert report date YYYYMMDD to following formats in scrip :

1. MMM-YY

2. YYYY

3. MM

4. DD

Thank you

Tracy

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Ah, that's a common weirdness in QlikView. And actually it isn't weird at all. All fields in QlikView are of type dual, meaning that they have both a numerical value and a string representation (or format). The MonthYear values in your data model are in reality dates with a day component. The first one is Oct 12, 2013, the second one is Oct 18, 2013. The string formatting that you use in your load script doesn't change the numerical value, but will assign a MMM-YY format string to that field.

The field values though remain different, while their representation looks the same. All objects in QlikView will list/order dimensions first on their numerical value.

Simple to solve: change the load script for MonthYear into something like:

LOAD Date,

     Date(MonthStart(Date), 'MMM-YY') as MonthYear,

:

and gone is your issue.

Best,

Peter

View solution in original post

20 Replies
sunny_talwar

Try this:

Table:

LOAD Date,

  Date(Date, 'MMM-YY') as MonthYear,

  Year(Date) as Year,

  Month(Date) as Month,

  Num(Month(Date)) as MonthNum,

  Day(Date) as Day;

LOAD Date#(Date,'YYYYMMDD') as Date,

     Amount

FROM

Test.xlsx

(ooxml, embedded labels, table is All);


Capture.PNG


Not applicable

First you need to convert your Input date field with DATE# function and then use date functions.

Please try like below:

LOAD

  *,

  Date(Date,'MMM-YYYY') as YearMonth,

  Year(Date) AS Year,

  Num(Month(Date),'00') AS Month,

  Num(Day(Date),'00') AS Day

;

LOAD

  Date#(Date,'YYYYMMDD') AS Date,

    Amount

FROM [Test (1).xlsx] (ooxml, embedded labels, table is All);

maxgro
MVP
MVP

add an interpretation function (Date#) to your script to

Date(Date#(Date, 'YYYYMMDD'),'MMM-YYYY') as YearMonth

and some other useful help on dates

Get the Dates Right

tracycrown
Creator III
Creator III
Author

Dear Sunny

The sum(Amount) is not working, please advise.

Thanks

Tracy

tracycrown
Creator III
Creator III
Author

Dear Dathu

Your method seems ok but it will not be correct for following data especially in Chart for October month (two bars instead of one). Also, please advise how to generate quarterly data.

   

DateAmount
201308022000
2013101230000
201307012500
201302154200
20131018295
2014070315000
201402192389

Thank you

Tracy

mightyqlikers
Creator III
Creator III

Dear Tracy,

Please find the below script

Directory;

LOAD Date,

  date(MakeDate(Left(Date,4),Mid(Date,5,2),Right(Date,2)),'DD-MM-YYYY') as DT, 

  date(MakeDate(Left(Date,4),Mid(Date,5,2),Right(Date,2)),'MMM-YYYY')  as MMMYYDT,

     Date(Date,'MMM-YYYY') as YearMonth,

     Amount

FROM

Test.xlsx

(ooxml, embedded labels, table is All);

Regards

$@M

tracycrown
Creator III
Creator III
Author

Dear Maxgro

Your method does not sort the month in ascending order.

   

MonthYearsum(Amount)
Jan-20132000
Aug-20142389
Jun-201415000
Oct-201330000

Thank you

Tracy

mightyqlikers
Creator III
Creator III

Try sorting by

sort month year by DT field

Regards
$@M.

tracycrown
Creator III
Creator III
Author

Dear Sam

YearMonth is not correct.

   

YearMonthsum(Amount)
May-570142000
Nov-5701630000
Feb-5704315000
Sep-570432389