Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
vikasshana
Creator II
Creator II

Exists and Not Exists is not working as expectec

Hi,

I do have the below example excel data which I'm loading into my application.

Sheet1:

vikasshana_1-1633282956047.png

Sheet2:

vikasshana_2-1633283026284.png

I've loaded both the sheets and below is the code and output.

Test1:
LOAD
A
FROM [lib://AttachedFiles/Test.xlsx]
(ooxml, embedded labels, table is Sheet1);

Test2:
LOAD
A1 as A 
FROM [lib://AttachedFiles/Test.xlsx]
(ooxml, embedded labels, table is Sheet2);

Output:

A
1
2
3
4

 

Now my requirement is I would like to take the resident of test2 and compare it with test1 and load the data exists and Non exists data into a new table.

Expected Output for exists

AStatus
1Exists
2Exists

 

Expected Output for not exists

AStatus
4Not Exists

 

Regards,

Vikas

5 Replies
Vegar
MVP
MVP

In Qlik Sense, when loading two data loads containing identical set of field names, the loads will automatically concatenate into one table. So in your script, the data from Test2 will autoconcatenate into your Test1 table.

 

I suggest you do the flag logic in the first loads like this. 

Test:

LOAD A, 'Exists' as Status FROM Test1Source;

Concatenate (Test)

LOAD A1 as A, if(exists(A,A1), 'Exists', 'Not Exists') as Status FROM Test2Source;

AshutoshBhumkar
Partner - Specialist
Partner - Specialist

Hi,

Below is the example. Let me know if that suffice your requirement or not.

E.g

Table1:
Load * Inline [
A
1
2
3
];

Table2:
Load * Inline [
A1
1
2
4
];

TableforExist:
Load
A1 as Dimension,
'Exists' as Status
Resident Table2 where Exists(A,A1);

Concatenate

TableForNotExist:
Load
A1 as Dimension,
'Not Exists' as Status
Resident Table2 where not Exists(A,A1);

 

Output:

AshutoshBhumkar_0-1633287695666.png

https://help.qlik.com/en-US/sense/August2021/Subsystems/Hub/Content/Sense_Hub/Scripting/InterRecordF...

 

Thanks,

Ashutosh

 

vikasshana
Creator II
Creator II
Author

Hi Vegar,

Thanks for your suggestion, I tried and I get the below Output.

AStatus
1Exists
2Exists
3Exists
4Not Exists

 

But I'm expecting below output.

AStatus
1Exists
2Exists
4Not Exists

 

Vegar
MVP
MVP

Try this: 

Test1:
Load A
FROM [lib://AttachedFiles/Test.xlsx]
(ooxml, embedded labels, table is Sheet1);

Test2:
NoConcatenate
Load
   A1 as A,
   if(exists(A,A1), 'Exists', 'Not Exists') as Status
FROM [lib://AttachedFiles/Test.xlsx]
(ooxml, embedded labels, table is Sheet2);

exit script;

(You might want to drop Test1 using DROP TABLE Test1; when script is run)

abhijitnalekar
Specialist II
Specialist II

Great @Vegar ,

 

Just one more point want to add one more point.

Uncheck include null values checkbox.

Regards,
Abhijit
keep Qliking...
Help users find answers! Don't forget to mark a solution that worked for you!