Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
piekepotloed
Contributor II
Contributor II

Help needed

  This is a small  part of my data:

DeelnemerPeildatum
70208

1-10-2015

702081-10-2014
702081-10-2013
252451-10-2015
252451-10-2014
252451-10-2012
252451-10-2008
252451-10-2007
658941-10-2015

I need to count the moments in peildatum. If the gap between the years is bigger than 3, the counting is stopped, A missing year between two records, needs to be counted.. So the result I need is in this table.

DeelnemerNumber of years
702083
252454
658941

Who has a solution for me, I ran out of idea's.

Thanks

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Ok, maybe something like this?

Set DateFormat = 'D-M-YYYY';

INPUT:

LOAD Deelnemer,

    Peildatum,

    Year(Peildatum) as Peilyear

FROM

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

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

TMP:

LOAD Deelnemer,

  If(Previous(Deelnemer) <> Deelnemer, 1, Rangesum( Peek('YearCount'), If(Peilyear >= Previous(Peilyear)-2, Previous(Peilyear)-Peilyear))) as YearCount,

  If(Previous(Deelnemer) <> Deelnemer, 0, Rangesum(Peek('StopFlag'),If(Peilyear < Previous(Peilyear)-2,1))) as StopFlag

Resident INPUT

ORDER BY Deelnemer, Peilyear desc;

Result:

LOAD Deelnemer,

  Max(YearCount) as YearCount

Resident TMP

WHERE StopFlag = 0

GROUP BY Deelnemer;

DROP TABLE TMP;

Deelnemer YearCount
252454
658941
702083

View solution in original post

4 Replies
swuehl
MVP
MVP

How do you get to 4 for 25245?

piekepotloed
Contributor II
Contributor II
Author

I've to count the missing year also, if the gap between two years is less than or equal to 3, so that's why i get to 4.

swuehl
MVP
MVP

Ok, maybe something like this?

Set DateFormat = 'D-M-YYYY';

INPUT:

LOAD Deelnemer,

    Peildatum,

    Year(Peildatum) as Peilyear

FROM

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

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

TMP:

LOAD Deelnemer,

  If(Previous(Deelnemer) <> Deelnemer, 1, Rangesum( Peek('YearCount'), If(Peilyear >= Previous(Peilyear)-2, Previous(Peilyear)-Peilyear))) as YearCount,

  If(Previous(Deelnemer) <> Deelnemer, 0, Rangesum(Peek('StopFlag'),If(Peilyear < Previous(Peilyear)-2,1))) as StopFlag

Resident INPUT

ORDER BY Deelnemer, Peilyear desc;

Result:

LOAD Deelnemer,

  Max(YearCount) as YearCount

Resident TMP

WHERE StopFlag = 0

GROUP BY Deelnemer;

DROP TABLE TMP;

Deelnemer YearCount
252454
658941
702083
piekepotloed
Contributor II
Contributor II
Author

Thanks for your quick response...it works