Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
haupenthals
Contributor III
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
stigchel
Partner - Master
Partner - Master

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

haupenthals
Contributor III
Contributor III
Author

Hi Piet!

thank you very much - it works perfectly!