Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
May 20, 2021 9:36:59 AM
Mar 27, 2019 10:38:05 AM
When using WHERE NOT Exists(<fieldName>) clause in a LOAD statement, the resulting table only contains a single row for each not-existing value of <fieldName>
For example, consider the following LOAD statements:
ID_table: LOAD * INLINE [ ID 1 ]; Data_table: LOAD * INLINE [ ID, Value 1, A 1, B 2, C 2, D 3, E 3, F ] WHERE NOT Exists(ID);
Expected result of Data_table after reload should be 4 rows with Value = C, D, E, F. However, actual result is that only 1 rows with Value = C,E are returned.
Environment:
This behavior is actually working as designed and is a common misconception - Where Not Exists is not exactly opposite with Where Exists in QlikView and Qlik Sense. The behavior is due to the line-by-line processing mechanism of Qlik engine. For example, in the above load statement:
The following blog post explains the behavior with a demonstration video: The Problem with Where Not Exists. Also refer to article How Is Data Stored In Qlik Sense And QlikView? for a discussion of how Qlik engine stores data in memory
The solution in this case is to rename the original ID field (for example ID1) and use WHERE NOT Exists(ID1, ID); instead. With this implementation, ID and ID1 are different fields, so they have different symbol tables and is not affected by the on-the-run update of the symbol table as shown above.
ID_table: LOAD ID as ID1; LOAD * INLINE [ ID 1 ]; Data_table: LOAD * INLINE [ ID, Value 1, A 1, B 2, C 2, D 3, E 3, F ] WHERE NOT Exists(ID1, ID);
But if I do this
WHERE NOT Exists(ID1, ID)
I lose my qvd load optimized 😢