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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to Script

I am new to VB type script and I am not sure if this should be done with a case statement or an IF statewment, but I cant seem to get it to work either way.
In the exmple below, I have an identical key for both lines but the condition field is different and so is the deal number.  I want to add a new field so that when these 2 conditions ZP06 and ZD05 exists for the same key, and their values are > 0 ,  I want the new field to have the Deal# in it that is related to the line with the ZP06 condition.
example
keyconditionvaluedeal
9316789436/000010ZD0510067890
9316789436/000010ZP0620012345
Result
keyconditionvaluedealnew field
9316789436/000010ZD051006789012345
9316789436/000010ZP0620012345

12345


Actually, better said, I only want to have 2 fields when I am done, the Key Field and the new field with the Deal# that relates to the ZP06 condition.  So, I would have a table like this,
keynew field
9316789436/000010

12345

Thanks, Sean
Labels (1)
3 Replies
Jason_Michaelides
Partner - Master II
Partner - Master II

Try this:

Data:

LOAD DISTINCT

  Key,

  If(Key=Previous(Key) AND Condition='ZP06' AND Previous(Condition)='ZP05' AND Value > 0 AND Previous(Value) > 0,Deal#) AS NewField

FROM...

ORDER BY Key,Condition,Value;

This will give you all values of 'Key' and some values of NewField will be NULL. If you want remove the null values then add:

Data2:

NoConcatenate

LOAD

  Key,

  NewField

RESIDENT Data

WHERE isNull(NewField)=0;

DROP TABLE Data:

Hope this helps,

Jason.

Not applicable
Author

Thanks but I am not getting the intended results.  Without an ELSE caluse I end up with nothing, when I add an else, I get results taht are incorrect.

Jason_Michaelides
Partner - Master II
Partner - Master II

Can you post some sample data?