Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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);
))
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
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.
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
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?
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.
Hello GaryGiles, I created an app from scratch as a test and that worked! Thank you!