Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
BigRed
Contributor II
Contributor II

Data Load Editor - Using an IF to reference a SET (Variable)

Hello Community, I'd like to SET a client name (e.g., 'MASS') and then per an IF reference that. In other words, at the beginning of the very first Section in the Data Load Editor, I'd like to be able to change 'MASS' to whatever (e.g., 'MARK') and then have subsequent LOAD's (managed by IF's) execute accordingly. 

Example:

SET vCLIENT = 'MASS';

IF('$(vCLIENT)'='MASS',
LOAD
Field1,
Field2,
Field3
FROM [lib://Pay:DataFiles/TableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);
,
IF('$(vCLIENT)'='MARK',
LOAD
Field4,
Field5,
Field6
FROM [lib://Owe:DataFiles/OweTableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);
,
LOAD
Field10,
Field12,
Field14
FROM [lib://Pmt:DataFiles/PmtTableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);
))

Labels (2)
2 Solutions

Accepted Solutions
GaryGiles
Specialist
Specialist

The syntax for If in a load script is

If <expression> Then

 . . . .

Else

if <expression> Then

. . . . .

End if

 

So, in your case:

SET vCLIENT = 'MASS';

IF '$(vCLIENT)'='MASS' then

LOAD
Field1,
Field2,
Field3
FROM [lib://Pay:DataFiles/TableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);

else

IF '$(vCLIENT)'='MARK' then

LOAD
Field4,
Field5,
Field6
FROM [lib://Owe:DataFiles/OweTableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);
Else
LOAD
Field10,
Field12,
Field14
FROM [lib://Pmt:DataFiles/PmtTableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);

End If

View solution in original post

GaryGiles
Specialist
Specialist

Is there any chance that there is another table that is loaded prior to this section being executed that has the name fields as the table you are trying to load in this logic.  If so, Qlik will perform an automatic table concatentation with the existing table.  To avoid that, you would need to add a Noconcatenate statement before you Load.

View solution in original post

4 Replies
GaryGiles
Specialist
Specialist

The syntax for If in a load script is

If <expression> Then

 . . . .

Else

if <expression> Then

. . . . .

End if

 

So, in your case:

SET vCLIENT = 'MASS';

IF '$(vCLIENT)'='MASS' then

LOAD
Field1,
Field2,
Field3
FROM [lib://Pay:DataFiles/TableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);

else

IF '$(vCLIENT)'='MARK' then

LOAD
Field4,
Field5,
Field6
FROM [lib://Owe:DataFiles/OweTableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);
Else
LOAD
Field10,
Field12,
Field14
FROM [lib://Pmt:DataFiles/PmtTableName.csv]
(txt, utf8, embedded labels, delimiter is ',', msq);

End If

BigRed
Contributor II
Contributor II
Author

Thank you GaryGiles, that does execute successfully. However, a table was not created and no fields are available for a visual. Note, I added MASS: and MARK: above each LOAD statement. Also, added EXIT SCRIPT; and the very bottom of the Section housing this syntax. Additionally, there are no other Sections in this test app.

Any thoughts as to why a table (and related fields) was not created?

GaryGiles
Specialist
Specialist

Is there any chance that there is another table that is loaded prior to this section being executed that has the name fields as the table you are trying to load in this logic.  If so, Qlik will perform an automatic table concatentation with the existing table.  To avoid that, you would need to add a Noconcatenate statement before you Load.

BigRed
Contributor II
Contributor II
Author

Hello GaryGiles, I created an app from scratch as a test and that worked! Thank you!