Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Counting months between startdate and EndDate

I am building a Qlik-report and I have a problem that I cannot solve. I have tried many different scripts "counting months between two dates". But those scripts aren't exact what I am looking for.

I need a script that can pickup the different of the dates 01, 15 and 16 for both StartDates and EndDates. The example below shows how the months are counting. The script should apply for the whole calendar from January to December

 

StartDateEndDateCount month
01.01.201815.06.20185
01.01.201816.06.20186
15.01.201815.06.20185
15.01.201816.06.20186
16.01.201815.06.20184
16.01.201816.06.20185

I appreciate any helps. Thanks

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

(Month(EndDate) + fabs(Day(EndDate)>15))

- (Month(StartDate)+ fabs(Day(StartDate)>15))

If you need to cross years, it just needs a small tweak to consider the year.

-Rob

http://masterssummit.com

http://qlikviewcookbook.com

View solution in original post

4 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

(Month(EndDate) + fabs(Day(EndDate)>15))

- (Month(StartDate)+ fabs(Day(StartDate)>15))

If you need to cross years, it just needs a small tweak to consider the year.

-Rob

http://masterssummit.com

http://qlikviewcookbook.com

maxgro
MVP
MVP

maybe

SET DateFormat='DD.MM.YYYY';

LOAD

    StartDate,

    if(day(StartDate) <= 15, MonthStart(StartDate), MonthStart(AddMonths(StartDate,1))) as ds,

    EndDate,

    if(day(EndDate) <= 15, MonthStart(EndDate), MonthStart(AddMonths(EndDate,1))) as de,

    [Count month]

FROM

[https://community.qlik.com/thread/292502]

(html, codepage is 1252, embedded labels, table is @1);



the expression in the chart is

Num(((year(de) * 12) + month(de)) - (((year(ds) * 12) + month(ds))) + 1) -1

1.png

Anonymous
Not applicable
Author

Thank you

The script works perfect

Anonymous
Not applicable
Author

The script of Rob Wunderlich is easier and shorter to use in my script.

Thank you for the solution. I will try your script in my report