Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

haupenthals
New Contributor III

How to load an additional table if a sum(field) = 0 in script

Hi Experts,

I would like to first load a table looking like this:

TAB:
LOAD * INLINE [
Article, QTY, Sales
a, 0, 1
a, 0, 1
a, 0, 5
a, 2, 1
a, 0, 5
b, 0, 5
b, 0, 5
c, 0, 5
c, 8, 5
c, 8, 5
]
;

Then, ONLY if the sum of 'b' = 0 load an additional table like this:

Concatenate (TAB)

LOAD * INLINE [
Article, QTY, Sales
b, 8, 1

];

I already tried (without success) with this part of script after the first inline table:

Controltab:
LOAD
sum(QTY) as Control_B
Resident TAB
Where Article= 'b';

if Control_B = 0 THEN

LOAD * INLINE [
Article, QTY, Sales
b, 8, 1

];
end if;

It doesn't load the new set of the second inline-table. If I removed the if-statement it loads.

Any idea what could help? Thank you in advance 🙂

2 Replies
Partner
Partner

Re: How to load an additional table if a sum(field) = 0 in script

Use the Peek function:

TAB:

LOAD * INLINE [

Article,QTY,Sales

a,0,1

a,0,1

a,0,5

a,2,1

a,0,5

b,0,5

b,0,5

c,0,5

c,8,5

c,8,5

];

Controltab:

LOAD

sum(QTY) as Control_B

Resident TAB Where Article='b';

LET B=Peek('Control_B',0,'Controltab');

DROP Table Controltab;

if $(B)=0 THEN

LOAD * INLINE [

Article,QTY,Sales

b,8,1

];

end if

Highlighted
haupenthals
New Contributor III

Re: How to load an additional table if a sum(field) = 0 in script

Hi Piet!

thank you very much - it works perfectly!