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: 
Not applicable

month difference

hi,

I have a table in which I have 2 columns like these :

01/09/2002200209
01/10/2002200209
01/12/2002200209
01/01/2003200209
01/02/2003200209
01/03/2003200209
01/04/2003200209
01/08/2003200209
01/09/2003200209
01/11/2003200209
01/12/2003200209
01/01/2004200209
01/03/2004200209
01/05/2004200209
01/06/2004200209
01/08/2004200209
01/09/2002200209
01/12/2002200209

Now I want to show the difference (in months) between the two, how can I achieve this?

6 Replies
sushil353
Master II
Master II

Hi,

Try This:

Month(Column1)-Month(Date(Date#(Column2,YYYYMM)))

HTH

Sushil

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

You need to take years into account with something like:

=(Year(Column1) * 12 + Month(Column1)) - (Left(Column2, 4)  * 12 + Right(Column2, 2))

HTH

Jonathan

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

Hi,

Try this ways

LOAD

Date(Date#(Date1,'DD/MM/YYYY'),'MM/YYYY') as NewDate1,

Date(Date#(Date2,'YYYYMM'),'MM/YYYY') as NewDate2,

Date(Date(Date#(Date1,'DD/MM/YYYY'),'MM/YYYY') - Date(Date#(Date2,'YYYYMM')),'MM') as NewDiff;

LOAD * Inline  [

Date1,Date2

01/09/2002,    200209

01/10/2002,    200209

01/12/2002,    200209

01/01/2003,    200209

01/02/2003,    200209

01/03/2003,    200209

01/04/2003,    200209

01/08/2003,    200209

01/09/2003,    200209

01/11/2003,    200209

01/12/2003,    200209

01/01/2004,    200209

01/03/2004,    200209

01/05/2004,    200209

01/06/2004,    200209

01/08/2004,    200209

01/09/2002,    200209

01/12/2002,    200209  ];

Regards

Anand

Not applicable
Author

hi Jonathan,

I had used this expression in the script, it errored out.

If I display existing columns as dimensions in a pivot table, I can't see them.

Is there a way to add a calculated dimension in a table box?

MarcoWedel

Hi,

one solution could be:

QlikCommunity_Thread_144644_Pic1.JPG.jpg

LOAD *,

    Month(date2)-Month(date1)+(Year(date2)-Year(date1))*12 as MonthDiff;

LOAD MonthName(Date#(date2,'DD/MM/YYYY')) as date2,

    MonthName(Date#(date1,'YYYYMM')) as date1

INLINE [

    date2, date1

    01/09/2002, 200209

    01/10/2002, 200209

    01/12/2002, 200209

    01/01/2003, 200209

    01/02/2003, 200209

    01/03/2003, 200209

    01/04/2003, 200209

    01/08/2003, 200209

    01/09/2003, 200209

    01/11/2003, 200209

    01/12/2003, 200209

    01/01/2004, 200209

    01/03/2004, 200209

    01/05/2004, 200209

    01/06/2004, 200209

    01/08/2004, 200209

    01/09/2002, 200209

    01/12/2002, 200209

];

hope this helps

regards

Marco

its_anandrjs

Hi,

There is another way for the doing the same problem is by

LOAD *,
Year(NewDate1) - Year(NewDate2) as YearDiff,
Month(NewDate1) - Month(NewDate2) as MonthDiff,
(
Year(NewDate1) - Year(NewDate2)) * 12 +
Month(NewDate1) - Month(NewDate2) as TotalMonDiff;
 

Load *,
Date(Date#(Date1,'DD/MM/YYYY'),'MM/YYYY') as NewDate1,
Date(Date#(Date2,'YYYYMM'),'MM/YYYY') as NewDate2;

LOAD * INLINE [
Date1, Date2
01/09/2002, 200209
01/10/2002, 200209
01/12/2002, 200209
01/01/2003, 200209
01/02/2003, 200209
01/03/2003, 200209
01/04/2003, 200209
01/08/2003, 200209
01/09/2003, 200209
01/11/2003, 200209
01/12/2003, 200209
01/01/2004, 200209
01/03/2004, 200209
01/05/2004, 200209
01/06/2004, 200209
01/08/2004, 200209
01/09/2002, 200209
01/12/2002, 200209
]
;

And you get table as

MonthDiff.png


Regards

Anand