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

How to Fill Continous Date in Qlikview ????

Hello All ,

I have a Scenario Where , I have date in such manner

CountryCALMONTHProduct Count
USAAug-015
USAOct-018
USANov-0110
USAJan-1115
UKAug-017
UKOct-018
UKNov-0110
UKJan-01

13

and i want data this format  in

CountryCALMONTHProduct Count
USAAug-015
USASep-015
USAOct-018
USANov-018
USADec-0110
USAJan-0210
USAFeb-0215
UKAug-017
UKSep-017
UKOct-018
UKNov-0110
UKDec-0110
UKJan-0213
UKFeb-02

13

Please Help me

Thanxs in Advance

1 Solution

Accepted Solutions
swuehl
MVP
MVP

In your result table for USA, Nov01, it should be 10 instead of 8, right?

Please look at attached sample file. I used two approaches (you need only one of them), I think most simple is:

INPUT:

LOAD Country,

     Date(Date#(CALMONTH,'MMM-YY'),'MMM-YY') as CALMONTH,

     [Product Count]

FROM

[http://community.qlik.com/thread/39299]

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

INPUT2:

LOAD Country as Country2, CALMONTH as CALMONTH_START, [Product Count] as [Product Count2],

if(peek(Country2)=Country, date(peek(CALMONTH_START)-1,'MMM-YY'), makedate(2002,02,28) ) as CALMONTH_END

resident INPUT order by Country, CALMONTH desc;

RESULT2:

LOAD

Date(addmonths(CALMONTH_START,iterno()-1),'MMM-YY') as CALMONTH2b

,Country2 as Country2b

,[Product Count2] as [Product Count2b]

resident INPUT2 WHILE addmonths(CALMONTH_START,iterno()-1) <= CALMONTH_END;

I think you could merge INPUT2 and INPUT loads, if you read in from your original data source.

The basic idea is to generate a end date for each record (just a little smaller than the next entry date for the next record of this country. Then use a while loop in the following load to create a record per country and product count from entry date to end date.

You could also use another approach using intervalmatch after you have created  the two dates, but that seems to be a little more complex.

Hope this helps,

Stefan

View solution in original post

9 Replies
Not applicable
Author

Some doubts:

1. In the first data set for US the month is Jan-11. Is that a typo?

2. In the first data set there is no Sep-01. Why does it appear in the second data set?

3. Why does Feb-02 appear in the second data set but Mar-02 does not appear in the second data set?

4. Why is Jan-02 product count not 15.

Also its good to post a qvw file.

Best Regards,
Vishal

Anonymous
Not applicable
Author

Sotty Guysssits a typo mistake

My data is in this format

CountryCALMONTHProduct Count
USAAug-015
USAOct-018
USANov-0110
USAJan-0215
UKAug-017
UKOct-018
UKNov-0110
UKJan-02

13

and i want data this format  in

CountryCALMONTHProduct Count
USAAug-015
USASep-015
USAOct-018
USANov-018
USADec-0110
USAJan-0210
USAFeb-0215
UKAug-017
UKSep-017
UKOct-018
UKNov-0110
UKDec-0110
UKJan-0213
UKFeb-02

13

please help me out and thanxs in advance

swuehl
MVP
MVP

In your result table for USA, Nov01, it should be 10 instead of 8, right?

Please look at attached sample file. I used two approaches (you need only one of them), I think most simple is:

INPUT:

LOAD Country,

     Date(Date#(CALMONTH,'MMM-YY'),'MMM-YY') as CALMONTH,

     [Product Count]

FROM

[http://community.qlik.com/thread/39299]

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

INPUT2:

LOAD Country as Country2, CALMONTH as CALMONTH_START, [Product Count] as [Product Count2],

if(peek(Country2)=Country, date(peek(CALMONTH_START)-1,'MMM-YY'), makedate(2002,02,28) ) as CALMONTH_END

resident INPUT order by Country, CALMONTH desc;

RESULT2:

LOAD

Date(addmonths(CALMONTH_START,iterno()-1),'MMM-YY') as CALMONTH2b

,Country2 as Country2b

,[Product Count2] as [Product Count2b]

resident INPUT2 WHILE addmonths(CALMONTH_START,iterno()-1) <= CALMONTH_END;

I think you could merge INPUT2 and INPUT loads, if you read in from your original data source.

The basic idea is to generate a end date for each record (just a little smaller than the next entry date for the next record of this country. Then use a while loop in the following load to create a record per country and product count from entry date to end date.

You could also use another approach using intervalmatch after you have created  the two dates, but that seems to be a little more complex.

Hope this helps,

Stefan

Anonymous
Not applicable
Author

Thanxs a Lot

Stefan

ur Solution Really Worked Out !!!!!!!!

Anonymous
Not applicable
Author

There is slight Change in Requirement

data is in this format

CountryProductYearMonth
USA200101
USC200104
USD200106
UKB200103
UKE200106
UKF200107
and now I want data in
CountryProduct YearMonth
USA200101
USA200102
USA200103
USA200104
USC200104
USA200105
USC200105
USA200106
USC200106
USD200106
UKB200103
UKB200104
UKB200105
UKB200106
UKE200106
UKB200107
UKE200107
UKF200107
Please Help  Me Out thnxs in advance
swuehl
MVP
MVP

Yes, that's a little different, if I understood correctly, like this:

Countries:

LOAD Country, Product, Date#(YearMonth,'YYYYMM') as YearMonth INLINE [

Country,    Product,    YearMonth

US,    A,    200101

US,    C,    200104

US,    D,    200106

UK,    B,    200103

UK,    E,    200106

UK,    F,    200107

];

Extrema:

LOAD Country, min(YearMonth) as minYM, max(YearMonth) as maxYM

resident Countries Group by Country;

 

Result:

NOCONCATENATE LOAD Country, Product, Date(addmonths(YearMonth,iterno()-1),'YYYYMM') as YearMonth

resident Countries while addmonths(YearMonth,iterno()-1)<=Lookup('maxYM','Country',Country,'Extrema') ;

drop tables Countries, Extrema;

Anonymous
Not applicable
Author

The End Date of Both US and UK should be todays YearMonth

how will it come ?

swuehl
MVP
MVP

Ok,

then it's even a little bit more simple:

Countries:

LOAD Country, Product, Date#(YearMonth,'YYYYMM') as YearMonth INLINE [

Country,    Product,    YearMonth

US,    A,    200101

US,    C,    200104

US,    D,    200106

UK,    B,    200103

UK,    E,    200106

UK,    F,    200107

];

  

Result:

NOCONCATENATE LOAD Country, Product, Date(addmonths(YearMonth,iterno()-1),'YYYYMM') as YearMonth

resident Countries while addmonths(YearMonth,IterNo()-1) <= today();

drop tables Countries;

Anonymous
Not applicable
Author

Thnxs a Lot

Stefan

4r helping me out

ur solution is just amazing