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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
noahfels
Contributor III
Contributor III

Check if record exists

I have a table looking like this (without column C):

noahfels_0-1635506951562.png

Now I want to create column C which indicates wheter a Material in A has at least one Material(Child) in B starting with a K.

As you can see in row 3, M20 has a K* Material(Child), therfore, all records with M20 should have a 1 (yes) in column C.

Same for M22, which has two K* Material(Child).

How do I generate this column C in the script?

1 Solution

Accepted Solutions
Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    Material(Parent), Material(Child)
    M20, R00
    M20, K01
    M20, L00
    M21, R00
    M21, L00
    M22, K20
    M22, K30
];

Left Join(tab1)
LOAD [Material(Parent)], If(Index(Concat(DISTINCT [Material(Child)] Like 'K*'),'-1'),1,0) As [Has_K*_Child]
Resident tab1
Group By [Material(Parent)];

commQV17.PNG

View solution in original post

3 Replies
Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    Material(Parent), Material(Child)
    M20, R00
    M20, K01
    M20, L00
    M21, R00
    M21, L00
    M22, K20
    M22, K30
];

Left Join(tab1)
LOAD [Material(Parent)], If(Index(Concat(DISTINCT [Material(Child)] Like 'K*'),'-1'),1,0) As [Has_K*_Child]
Resident tab1
Group By [Material(Parent)];

commQV17.PNG

noahfels
Contributor III
Contributor III
Author

Thanks a lot this works perfectly. 
However I do not quite understand why Concat returns -10 if there is a K*Child.
Furthermore, is the if-statement in Qlik always true when the condition is any number except for 0 or how does it work?

 

Saravanan_Desingh

I am concatenating the conditional statement here ([Material(Child)] Like 'K*'). So this will return either -1 or 0.