Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Load missing fields as 0

Dear all,

I have spent quite a lot of time with the following issue, but I'm still not able to get a result which I would need. I have data which are preloaded via SQL load to the qvd file. Once I load data to the qvd file I need to load data to my QV report and work with these data here.

Data structure - Source QVD file contains Week, Item number and Quantity. Basically these data present consumption of item for each week in past 52 weeks. The problem is that there is no record for combination week and item no. if there was no consumption in the week. If I load all the data as they are in the QVD, I can suppress missing values and display them as 0, but I cannot count(AVG, STDEV, etc) with these 0 characters, because it just a visual substitution.

So my question is if there is any easy way how to load item number and quantity for all 52 weeks with 0 in weeks for which there is no record in the qvd file and enter actual quantity if record exists? We have tried to modify SQL select for qvd file, but it is not an option. I'm running out of ideas how to archive this functionality. I tried also do while below, but without success.

SET vWEEKS=1;

DO while $(vWEEKS)<52

LINES_CONS:

LOAD ITNO, IF(WEEK=$(vWEEKS),WEEK,$(vWEEKS)) as WEEK, IF(QTY<>),QTY,0) as QTY

FROM

\\DATA\file.qvd

(qvd);

Do you have any advice for me how to proceed with this load? Many thanks in advance.

QVD Data                                 What I need.

WeekItem No.Quantity
1A5
1B3
1C5
2B7
2C12
3A4
3C56
5C34
WeekItem No.Quantity
1A5
1B3
1C5
2A0
2B7
2C12
3A4
3B0
3C56
4A0
4B0
4C0
5A0
5B0
5C34
1 Solution

Accepted Solutions
MarcoWedel

Hi,

one solution could be also:

QlikCommunity_Thread_189927_Pic1.JPG

tabQVDData:

LOAD * FROM [https://community.qlik.com/thread/189927] (html, codepage is 1252, embedded labels, table is @2);

Left Join (tabQVDData)

LOAD Distinct Week, [Item No.], AutoNumberHash128(Week, [Item No.]) as TempID Resident tabQVDData;

tabTemp:

LOAD RecNo() as Week AutoGenerate 52;

Left Join (tabTemp)

LOAD Distinct [Item No.] Resident tabQVDData;

Concatenate (tabQVDData)

LOAD Week,

    [Item No.],

    0 as Quantity

Resident tabTemp

Where not Exists(TempID, AutoNumberHash128(Week, [Item No.]));

DROP Field TempID;

DROP Table tabTemp;

hope this helps

regards

Marco

View solution in original post

6 Replies
maxgro
MVP
MVP

RESULT

1.png

SCRIPT

// load source data

Source:

LOAD Week,

     [Item No.],

     Quantity

FROM

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

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

// make all weeks x all item (full outer join), no quantity field

Tmp:

load min(Week) as MinWeek, max(Week) as MaxWeek

Resident Source;

LET vMinWeek=Peek('MinWeek');

LET vMaxWeek=Peek('MaxWeek');

DROP Table Tmp;

WeeksXProduct:

load $(vMinWeek) + RowNo() -1 as Week

AutoGenerate ($(vMaxWeek)-$(vMinWeek)+1);

join (WeeksXProduct)

load Distinct [Item No.]

Resident Source;

// add quantity field from source

left join (WeeksXProduct)

load Week, [Item No.], Quantity

Resident Source;

// replace null (no quantity in source data) with 0

Final:

NoConcatenate load Week, [Item No.], alt(Quantity,0) as Quantity

Resident WeeksXProduct;

DROP Table WeeksXProduct;

MarcoWedel

Hi,

one solution could be also:

QlikCommunity_Thread_189927_Pic1.JPG

tabQVDData:

LOAD * FROM [https://community.qlik.com/thread/189927] (html, codepage is 1252, embedded labels, table is @2);

Left Join (tabQVDData)

LOAD Distinct Week, [Item No.], AutoNumberHash128(Week, [Item No.]) as TempID Resident tabQVDData;

tabTemp:

LOAD RecNo() as Week AutoGenerate 52;

Left Join (tabTemp)

LOAD Distinct [Item No.] Resident tabQVDData;

Concatenate (tabQVDData)

LOAD Week,

    [Item No.],

    0 as Quantity

Resident tabTemp

Where not Exists(TempID, AutoNumberHash128(Week, [Item No.]));

DROP Field TempID;

DROP Table tabTemp;

hope this helps

regards

Marco

petter
Partner - Champion III
Partner - Champion III

Yet another solution could be - without the use of joins but using ApplyMap() and a Mapping Table:

2015-11-03 #1.PNG

2015-11-03 #2.PNG

jonathandienst
Partner - Champion III
Partner - Champion III

Also read this article:

How to populate a sparsely populated field

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Thanks a lot for advices. I will look at it later today and I will let you know. I really appreciate such a nice reaction from the comunity.

Not applicable
Author

Hi,

Thanks. I used this one as a solution, because it was easier for me to understand the logic behind, but all solutions here were helpfull, because it shows me different ways how to resolve the issue. Also the article provided below was usefull for me. Thanks to all who replied me.