0

I am having an issue creating an alias name while looping in qlik sense. Below are my 2 code versions both not successful, nothing wrong with the joins or resident tables.

Version 1

// Define an array of phone types
SET phoneTypes = 'CELLPHONE', 'WORKPHONE';


// Loop through each phone type and perform the join for the first set of fields
FOR each phoneType IN phoneTypes
    FOR i = 0 TO 2
        LET j = i + 1;
        LEFT JOIN (table1)
        LOAD DISTINCT
            FIELDA as $(phoneType)_FIELDA$(j),
            Date(Date(CREATEDDATE)-$(i)) as CREATEDDATE,
            $(phoneType) as PHONENUMBER
        Resident table2;
    NEXT
NEXT

Version 2

// Define an array of phone types
SET phoneTypes = 'CELLPHONE', 'WORKPHONE';


// Loop through each phone type and perform the join for the first set of fields
FOR each phoneType IN phoneTypes
    FOR i = 0 TO 2
        LET j = i + 1;
        LEFT JOIN (table1)
        LOAD DISTINCT
            FIELDA as $(phoneType)&'_FIELDA'&$(j),
            Date(Date(CREATEDDATE)-$(i)) as CREATEDDATE,
            $(phoneType) as PHONENUMBER
        Resident table2;
    NEXT
NEXT

1 Answer 1

0

You have to tell Qlik to evaluate phoneTypes varable, when defining the loop:

set phoneTypes = 'CELLPHONE', 'WORKPHONE';

for each phoneType in $(phoneTypes) // evaluate the variable
    trace Phone type: $(phoneType);
next

And the reload will print the iteration value:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.