Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How can I re-reference a custom fields in the script?

I have two custom fields created in my script;

if( blah blah, 'True','False') as T1

if(blah blah, 'True','False') as T2

How would I create a third field such as:

If(T1 = 'True' and T2 = 'True, 'True', 'False') as T3

At the moment it's erroring as I don't think I can use a custom field in another custom field??

Thanks!!!! Mike

1 Solution

Accepted Solutions
vidyut
Partner - Creator II
Partner - Creator II

In the single load you cannot use the custom fields to define another new field.

To do that, you could use a preceding load, which would be the best in this case:

Load

If(T1='True' and T2='True','True','False') as T3,

*; //Notice how we don't specify the Tablename in the preceding load....

Load

if( blah blah, 'True','False') as T1,

if(blah blah, 'True','False') as T2

Resident BlahTable;

View solution in original post

4 Replies
Miguel_Angel_Baeyens

Hello Mike,

Since these values are in the same record, use the same conditionals for t3, like

If(If(blah blah, 'True', 'False') = 'True' AND If(blah blah, 'True', 'False') = 'True', 'True', 'False') AS T3


Hope that helps.

Not applicable
Author

Thanks for that... I considered that option but actually I have T1 - T7 and the if statements are complex so didn't really want to duplicate... would be tricky to edit down the line.

If no other option then that's what I'll do Smile but wondering if there is anything tidier? Confused

Miguel_Angel_Baeyens

Hi,

You can do two loads, one with T1 and T2 (according to your example) and the second with T3. But anyway you may loop through all possible values and tables:

Step1:LOAD If(Condition) AS T1, If(Condition2) AS T2FROM Source; Step2:LOAD *, If(T1 = 'True' AND T2 = 'True', 'True', 'False') AS T3RESIDENT Step1; DROP TABLE Step1; // needed to avoid unwanted synthetic keys


Anyway, looping in may experience is always slower than creating those 7 fields in one load.

Hope that helps.

vidyut
Partner - Creator II
Partner - Creator II

In the single load you cannot use the custom fields to define another new field.

To do that, you could use a preceding load, which would be the best in this case:

Load

If(T1='True' and T2='True','True','False') as T3,

*; //Notice how we don't specify the Tablename in the preceding load....

Load

if( blah blah, 'True','False') as T1,

if(blah blah, 'True','False') as T2

Resident BlahTable;