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: 
Ceb
Contributor III
Contributor III

Filling in missing dates for multiple Categories in Qlik-Sense

Hi,

I have read multiple posts related to handling missing dates. But I am not sure how to do it for my case over here.

Assume my below dataset.

GroupStatesDate initiatedTotal Sales
AFl4-Jan-193
AFl7-Jan-192
ANY3-Jan-192
AMA6-Jan-192
BMA11-Jan-191
BMA14-Jan-191
BNH4-Jan-191
BNH6-Jan-191

 

I have 2 groups and 4 different states. In the visualization I will create a master table with all this data and use filter to filter out programs and states.

In the above data-set I have missing dates for states. How should I go about filling the missing dates and even put zero in Total Sales for the missing dates. I have done it for a single group previously but this has multiple groups, so it is kind of confusing.

I need something like this.

GroupProgramDate initiatedTotal Sales
AFl1-Jan-190
AFl2-Jan-190
AFl3-Jan-190
AFl4-Jan-193
AFl5-Jan-190
AFl6-Jan-190
AFl7-Jan-192
AFl8-Jan-190
AFl9-Jan-190
AFl10-Jan-190
ANY1-Jan-190
ANY2-Jan-190
ANY3-Jan-192
ANY4-Jan-190
ANY5-Jan-190
ANY6-Jan-190
ANY7-Jan-190
ANY8-Jan-190
ANY9-Jan-190
ANY10-Jan-190

And so on.....

I can do it SQL but filtering it out and then using a LEFT JOIN with a master calendar and then do a UNION of all the data but I was thinking if I can work something in Qlik-Sense itself.

 

Thanks

Labels (3)
1 Solution

Accepted Solutions
Nicole-Smith

This load script looks to work:

 

/* Original data */
Data:
LOAD * INLINE [
    Group, States, Date initiated, Total Sales
    A, Fl, 2019-01-04, 3
    A, Fl, 2019-01-07, 2
    A, NY, 2019-01-03, 2
];

/* Create a calendar */
LET vMinDate = MakeDate(2019, 1, 1);
LET vMaxDate = MakeDate(2019,1,10);

AllDates:
LOAD Date('$(vMinDate)' + IterNo() - 1) AS [Date initiated]
AutoGenerate 1
WHILE '$(vMinDate)' + IterNo() - 1 <= '$(vMaxDate)';

/* Get list of Groups and States */
Temp:
LOAD DISTINCT Group, States
RESIDENT Data;

/* Adding all dates */
LEFT JOIN (Temp)
LOAD [Date initiated]
RESIDENT AllDates;

/* Adding values */
LEFT JOIN (Temp)
LOAD *
RESIDENT Data;

DROP TABLES Data, AllDates;

/* Replacing nulls with zeroes */
NullAsValue [Total Sales];
Set NullValue = 0;

Final:
NOCONCATENATE LOAD *
RESIDENT Temp;

DROP TABLE Temp;

 

 

It returns this table:

Group States Date initiated Total Sales 
AFl1/1/20190
AFl1/2/20190
AFl1/3/20190
AFl1/4/20193
AFl1/5/20190
AFl1/6/20190
AFl1/7/20192
AFl1/8/20190
AFl1/9/20190
AFl1/10/20190
ANY1/1/20190
ANY1/2/20190
ANY1/3/20192
ANY1/4/20190
ANY1/5/20190
ANY1/6/20190
ANY1/7/20190
ANY1/8/20190
ANY1/9/20190
ANY1/10/20190

View solution in original post

2 Replies
Nicole-Smith

This load script looks to work:

 

/* Original data */
Data:
LOAD * INLINE [
    Group, States, Date initiated, Total Sales
    A, Fl, 2019-01-04, 3
    A, Fl, 2019-01-07, 2
    A, NY, 2019-01-03, 2
];

/* Create a calendar */
LET vMinDate = MakeDate(2019, 1, 1);
LET vMaxDate = MakeDate(2019,1,10);

AllDates:
LOAD Date('$(vMinDate)' + IterNo() - 1) AS [Date initiated]
AutoGenerate 1
WHILE '$(vMinDate)' + IterNo() - 1 <= '$(vMaxDate)';

/* Get list of Groups and States */
Temp:
LOAD DISTINCT Group, States
RESIDENT Data;

/* Adding all dates */
LEFT JOIN (Temp)
LOAD [Date initiated]
RESIDENT AllDates;

/* Adding values */
LEFT JOIN (Temp)
LOAD *
RESIDENT Data;

DROP TABLES Data, AllDates;

/* Replacing nulls with zeroes */
NullAsValue [Total Sales];
Set NullValue = 0;

Final:
NOCONCATENATE LOAD *
RESIDENT Temp;

DROP TABLE Temp;

 

 

It returns this table:

Group States Date initiated Total Sales 
AFl1/1/20190
AFl1/2/20190
AFl1/3/20190
AFl1/4/20193
AFl1/5/20190
AFl1/6/20190
AFl1/7/20192
AFl1/8/20190
AFl1/9/20190
AFl1/10/20190
ANY1/1/20190
ANY1/2/20190
ANY1/3/20192
ANY1/4/20190
ANY1/5/20190
ANY1/6/20190
ANY1/7/20190
ANY1/8/20190
ANY1/9/20190
ANY1/10/20190
Ceb
Contributor III
Contributor III
Author

This works great!!!

 

Thanks a lot